0001-Reject-overflows-of-zip-header-fields-in-minizip.patch 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. From 73331a6a0481067628f065ffe87bb1d8f787d10c Mon Sep 17 00:00:00 2001
  2. From: Hans Wennborg <hans@chromium.org>
  3. Date: Fri, 18 Aug 2023 11:05:33 +0200
  4. Subject: [PATCH] Reject overflows of zip header fields in minizip.
  5. This checks the lengths of the file name, extra field, and comment
  6. that would be put in the zip headers, and rejects them if they are
  7. too long. They are each limited to 65535 bytes in length by the zip
  8. format. This also avoids possible buffer overflows if the provided
  9. fields are too long.
  10. Upstream: https://github.com/madler/zlib/commit/73331a6a0481067628f065ffe87bb1d8f787d10c
  11. Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  12. ---
  13. contrib/minizip/zip.c | 11 +++++++++++
  14. 1 file changed, 11 insertions(+)
  15. diff --git a/contrib/minizip/zip.c b/contrib/minizip/zip.c
  16. index 3d3d4cadd..0446109b2 100644
  17. --- a/contrib/minizip/zip.c
  18. +++ b/contrib/minizip/zip.c
  19. @@ -1043,6 +1043,17 @@ extern int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char* filename, c
  20. return ZIP_PARAMERROR;
  21. #endif
  22. + // The filename and comment length must fit in 16 bits.
  23. + if ((filename!=NULL) && (strlen(filename)>0xffff))
  24. + return ZIP_PARAMERROR;
  25. + if ((comment!=NULL) && (strlen(comment)>0xffff))
  26. + return ZIP_PARAMERROR;
  27. + // The extra field length must fit in 16 bits. If the member also requires
  28. + // a Zip64 extra block, that will also need to fit within that 16-bit
  29. + // length, but that will be checked for later.
  30. + if ((size_extrafield_local>0xffff) || (size_extrafield_global>0xffff))
  31. + return ZIP_PARAMERROR;
  32. +
  33. zi = (zip64_internal*)file;
  34. if (zi->in_opened_file_inzip == 1)