diff --git a/decompress/7zip_support.c b/decompress/7zip_support.c index 74c768c1af..37c739b5e6 100644 --- a/decompress/7zip_support.c +++ b/decompress/7zip_support.c @@ -100,8 +100,7 @@ static Bool Utf16_To_Utf8(uint8_t *dest, size_t *destLen, dest[destPos] = (char)(0x80 + ((value >> (6 * numAdds)) & 0x3F)); destPos++; - } - while (numAdds != 0); + }while (numAdds != 0); } *destLen = destPos; return False; @@ -261,7 +260,7 @@ int read_7zip_file( SzArEx_GetFileNameUtf16(&db, i, temp); res = ConvertUtf16toCharString(temp,infile); - if (strcmp(infile,relative_path) == 0) + if (!strcmp(infile, relative_path)) { /* C LZMA SDK does not support chunked extraction - see here: * sourceforge.net/p/sevenzip/discussion/45798/thread/6fb59aaf/ @@ -409,7 +408,8 @@ struct string_list *compressed_7zip_file_list_new(const char *path, { free(temp); tempSize = len; - temp = (uint16_t *)malloc(tempSize * sizeof(temp[0])); + temp = (uint16_t *)malloc(tempSize * sizeof(temp[0])); + if (temp == 0) { res = SZ_ERROR_MEM; diff --git a/decompress/zip_support.c b/decompress/zip_support.c index 5852d21fcd..f04d8fae16 100644 --- a/decompress/zip_support.c +++ b/decompress/zip_support.c @@ -19,10 +19,11 @@ #include #include #include - #include + #include #include + #include "zip_support.h" #include "../deps/zlib/unzip.h" @@ -92,7 +93,7 @@ int read_zip_file(const char *archive_path, { /* We skip directories */ } - else if (!strcmp(filename,relative_path)) + else if (!strcmp(filename, relative_path)) { /* We found the correct file in the zip, * now extract it to *buf. */ @@ -103,7 +104,24 @@ int read_zip_file(const char *archive_path, goto error; } - if (optional_outfile != 0) + if (optional_outfile == 0) + { + /* Allocate outbuffer */ + *buf = malloc(file_info.uncompressed_size + 1 ); + bytes_read = unzReadCurrentFile(zipfile, *buf, file_info.uncompressed_size); + + if (bytes_read != (ssize_t)file_info.uncompressed_size) + { + RARCH_ERR( + "Tried to read %d bytes, but only got %d of file %s in ZIP %s.\n", + (unsigned int) file_info.uncompressed_size, (int)bytes_read, + relative_path, archive_path); + free(*buf); + goto close; + } + ((char*)(*buf))[file_info.uncompressed_size] = '\0'; + } + else { char read_buffer[RARCH_ZIP_SUPPORT_BUFFER_SIZE_MAX] = {0}; FILE* outsink = fopen(optional_outfile,"wb"); @@ -135,23 +153,6 @@ int read_zip_file(const char *archive_path, fclose(outsink); } - else - { - /* Allocate outbuffer */ - *buf = malloc(file_info.uncompressed_size + 1 ); - bytes_read = unzReadCurrentFile(zipfile, *buf, file_info.uncompressed_size); - - if (bytes_read != (ssize_t)file_info.uncompressed_size) - { - RARCH_ERR( - "Tried to read %d bytes, but only got %d of file %s in ZIP %s.\n", - (unsigned int) file_info.uncompressed_size, (int)bytes_read, - relative_path, archive_path); - free(*buf); - goto close; - } - ((char*)(*buf))[file_info.uncompressed_size] = '\0'; - } finished_reading = true; }