Skip to content

Commit

Permalink
Restore archive_file_7z.c
Browse files Browse the repository at this point in the history
  • Loading branch information
LibretroAdmin committed Jan 7, 2025
1 parent 69e8be6 commit a98ab48
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions libretro-common/file/archive_file_7z.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;

Expand All @@ -437,28 +436,33 @@ 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);
}

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);
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit a98ab48

Please sign in to comment.