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:
Acts1631
2026-10-05 19:53:06 -04:00
parent 70ccb3acfc
commit f3fed4d15a
3 changed files with 15 additions and 6 deletions
+5 -2
View File
@@ -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
View File
@@ -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
View File
@@ -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);