diff --git a/libretro-common/file/archive_file_7z.c b/libretro-common/file/archive_file_7z.c index cb561062a37..adcb15a3bb2 100644 --- a/libretro-common/file/archive_file_7z.c +++ b/libretro-common/file/archive_file_7z.c @@ -414,7 +414,6 @@ static int sevenzip_parse_file_init(file_archive_transfer_t *state, static int sevenzip_parse_file_iterate_step_internal( struct sevenzip_context_t *sevenzip_context, char *s, - size_t len, const uint8_t **cdata, unsigned *cmode, uint32_t *size, @@ -425,7 +424,7 @@ static int sevenzip_parse_file_iterate_step_internal( { if (sevenzip_context->parse_index < sevenzip_context->db.NumFiles) { - size_t len = SzArEx_GetFileNameUtf16(&sevenzip_context->db, + size_t _len = SzArEx_GetFileNameUtf16(&sevenzip_context->db, sevenzip_context->parse_index, NULL); uint64_t compressed_size = 0; @@ -437,21 +436,24 @@ static int sevenzip_parse_file_iterate_step_internal( sevenzip_context->packIndex++; } - if ( (len < PATH_MAX_LENGTH) + if ( (_len < PATH_MAX_LENGTH) && !SzArEx_IsDir(&sevenzip_context->db, sevenzip_context->parse_index)) { + char infile[PATH_MAX_LENGTH]; SRes res = SZ_ERROR_FAIL; - uint16_t *temp = (uint16_t*)malloc(len * sizeof(uint16_t)); + uint16_t *temp = (uint16_t*)malloc(_len * sizeof(uint16_t)); if (!temp) return -1; + infile[0] = '\0'; + SzArEx_GetFileNameUtf16(&sevenzip_context->db, sevenzip_context->parse_index, temp); if (temp) { - res = utf16_to_char_string(temp, s, len) + res = utf16_to_char_string(temp, infile, sizeof(infile)) ? SZ_OK : SZ_ERROR_FAIL; free(temp); } @@ -459,6 +461,8 @@ static int sevenzip_parse_file_iterate_step_internal( if (res != SZ_OK) return -1; + strlcpy(s, infile, PATH_MAX_LENGTH); + *cmode = 0; /* unused for 7zip */ *checksum = sevenzip_context->db.CRCs.Vals[sevenzip_context->parse_index]; *size = (uint32_t)SzArEx_GetFileSize(&sevenzip_context->db, sevenzip_context->parse_index); @@ -492,7 +496,6 @@ static int sevenzip_parse_file_iterate_step(void *context, ret = sevenzip_parse_file_iterate_step_internal(sevenzip_context, userdata->current_file_path, - sizeof(userdata->current_file_path), &cdata, &cmode, &size, &csize, &checksum, &payload, userdata);