Skip to content

Commit

Permalink
cpl_zipOpenNewFileInZip3(): validate length of filename, comment and …
Browse files Browse the repository at this point in the history
…extrafields (CVE-2023-45853)

Backport of madler/zlib#843
  • Loading branch information
rouault committed Nov 4, 2023
1 parent 6e2afd1 commit 725070c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions port/cpl_minizip_zip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,17 @@ extern int ZEXPORT cpl_zipOpenNewFileInZip3(
if (filename == nullptr)
filename = "-";

// The filename and comment length must fit in 16 bits.
if ((filename != nullptr) && (strlen(filename) > 0xffff))
return ZIP_PARAMERROR;
if ((comment != nullptr) && (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;

if (comment == nullptr)
size_comment = 0;
else
Expand Down

0 comments on commit 725070c

Please sign in to comment.