Skip to content

Commit

Permalink
Guard against malformed input files
Browse files Browse the repository at this point in the history
Ensure the archive start offset can never be negative.
Fixes a case found by OSSFuzz.
  • Loading branch information
LemonBoy committed Jun 10, 2024
1 parent 3c46a05 commit 0283a17
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions miniz_zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,9 @@ static int mz_stat64(const char *path, struct __stat64 *buffer)
if ((cdir_ofs + (mz_uint64)cdir_size) > pZip->m_archive_size)
return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);

if (eocd_ofs < cdir_ofs + cdir_size)
return mz_zip_set_error(pZip, MZ_ZIP_INVALID_HEADER_OR_CORRUPTED);

/* The end of central dir follows the central dir, unless the zip file has
* some trailing data (e.g. it is appended to an executable file). */
archive_ofs = eocd_ofs - (cdir_ofs + cdir_size);
Expand Down

0 comments on commit 0283a17

Please sign in to comment.