summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Wennborg <hans@chromium.org>2023-08-18 11:05:33 +0200
committerXavier Roche <roche@httrack.com>2023-11-18 11:01:28 +0100
commit8316bc0e974c2a84a35f2175d413804c9b5be90c (patch)
tree83046f6fdea8417ec9f001487d622e66ba0e3681
parent6b56ea91a4ed4c8d8f14ee7e6f5a1207061c69d9 (diff)
Reject overflows of zip header fields in minizip.
This checks the lengths of the file name, extra field, and comment that would be put in the zip headers, and rejects them if they are too long. They are each limited to 65535 bytes in length by the zip format. This also avoids possible buffer overflows if the provided fields are too long. (cherry picked from commit 73331a6a0481067628f065ffe87bb1d8f787d10c)
-rw-r--r--src/minizip/zip.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/minizip/zip.c b/src/minizip/zip.c
index cd525d2..9affa61 100644
--- a/src/minizip/zip.c
+++ b/src/minizip/zip.c
@@ -1083,6 +1083,17 @@ extern int ZEXPORT zipOpenNewFileInZip4_64 (zipFile file, const char* filename,
return ZIP_PARAMERROR;
#endif
+ // The filename and comment length must fit in 16 bits.
+ if ((filename!=NULL) && (strlen(filename)>0xffff))
+ return ZIP_PARAMERROR;
+ if ((comment!=NULL) && (strlen(comment)>0xffff))
+ return ZIP_PARAMERROR;
+ // The extra field length must fit in 16 bits. If the member also requires
+ // a Zip64 extra block, that will also need to fit within that 16-bit
+ // length, but that will be checked for later.
+ if ((size_extrafield_local>0xffff) || (size_extrafield_global>0xffff))
+ return ZIP_PARAMERROR;
+
zi = (zip64_internal*)file;
if (zi->in_opened_file_inzip == 1)