mirror of
https://github.com/ekeeke/Genesis-Plus-GX.git
synced 2026-10-11 22:39:54 +00:00
Bound ZIP extraction before narrowing its size
The SDL, GCW0, and PSP2 loaders converted the archive's unsigned uncompressed size to int before comparing it with the ROM buffer limit. Values above INT_MAX became negative and were passed to the unzip API as a large unsigned length, allowing decompression past the ROM buffer. Compare in the archive size type and narrow only after applying the destination limit.
This commit is contained in:
+5
-2
@@ -91,11 +91,14 @@ int load_archive(char *filename, unsigned char *buffer, int maxsize, char *exten
|
||||
}
|
||||
|
||||
/* Retrieve uncompressed file size */
|
||||
size = info.uncompressed_size;
|
||||
if(size > maxsize)
|
||||
if(info.uncompressed_size > (uLong)maxsize)
|
||||
{
|
||||
size = maxsize;
|
||||
}
|
||||
else
|
||||
{
|
||||
size = info.uncompressed_size;
|
||||
}
|
||||
|
||||
/* Read (decompress) the file */
|
||||
ret = unzReadCurrentFile(fd, buffer, size);
|
||||
|
||||
+5
-2
@@ -91,11 +91,14 @@ int load_archive(char *filename, unsigned char *buffer, int maxsize, char *exten
|
||||
}
|
||||
|
||||
/* Retrieve uncompressed file size */
|
||||
size = info.uncompressed_size;
|
||||
if(size > maxsize)
|
||||
if(info.uncompressed_size > (uLong)maxsize)
|
||||
{
|
||||
size = maxsize;
|
||||
}
|
||||
else
|
||||
{
|
||||
size = info.uncompressed_size;
|
||||
}
|
||||
|
||||
/* Read (decompress) the file */
|
||||
ret = unzReadCurrentFile(fd, buffer, size);
|
||||
|
||||
+5
-2
@@ -91,11 +91,14 @@ int load_archive(char *filename, unsigned char *buffer, int maxsize, char *exten
|
||||
}
|
||||
|
||||
/* Retrieve uncompressed file size */
|
||||
size = info.uncompressed_size;
|
||||
if(size > maxsize)
|
||||
if(info.uncompressed_size > (uLong)maxsize)
|
||||
{
|
||||
size = maxsize;
|
||||
}
|
||||
else
|
||||
{
|
||||
size = info.uncompressed_size;
|
||||
}
|
||||
|
||||
/* Read (decompress) the file */
|
||||
ret = unzReadCurrentFile(fd, buffer, size);
|
||||
|
||||
Reference in New Issue
Block a user