NokiaTube | New address | Mode Desktop | On high quality
Skip to content

Fix zip slip path traversal and integer overflow in zip arrays - #403

Open
ph4nt0mbyt3 wants to merge 1 commit into
richgel999:masterfrom
ph4nt0mbyt3:fix/zip-path-traversal-and-overflow
Open

ph4nt0mbyt3 wants to merge 1 commit into
richgel999:masterfrom
ph4nt0mbyt3:fix/zip-path-traversal-and-overflow

Conversation

@ph4nt0mbyt3

Copy link
Copy Markdown

Summary

Fix two security issues in miniz's ZIP handling.

Bug 1: Zip Slip Path Traversal in mz_zip_reader_file_stat

Filenames from the ZIP central directory are copied into pStat->m_filename without any path sanitization. Applications that use this filename to construct extraction paths are vulnerable to directory traversal attacks.

A crafted ZIP archive can contain entries with filenames like ../../etc/cron.d/backdoor or /tmp/evil. When extracted, these write files outside the intended directory.

Fix: Validate filenames in mz_zip_reader_file_stat immediately after copying from the central directory header. Reject filenames that:

  • Start with / or \ (absolute paths)
  • Contain .. (directory traversal)
  • Contain embedded NUL bytes
  • Start with a drive letter prefix like C: (Windows absolute paths)

Bug 2: Integer Overflow in mz_zip_array_ensure_room / mz_zip_array_push_back

Both functions compute pArray->m_size + n without checking for size_t overflow. On 32-bit platforms, when m_size is large and n is chosen to wrap the addition, the result is a small value. This leads to an undersized allocation, followed by a heap buffer overflow when memcpy writes n * m_element_size bytes into the too-small buffer.

Fix: Check that m_size + n does not wrap (i.e., the sum is not less than either operand) before proceeding with the allocation.

Impact

  • Zip Slip: Arbitrary file write outside extraction directory via crafted ZIP
  • Integer Overflow: Heap buffer overflow on 32-bit platforms via crafted ZIP with many entries or large central directory

1. mz_zip_reader_file_stat: Reject filenames containing "..",
   starting with "/" or "\", with embedded NUL bytes, or (on
   Windows) with drive letter prefixes like "C:". These path
   traversal patterns allow a crafted ZIP to write files outside
   the intended extraction directory.

2. mz_zip_array_ensure_room / mz_zip_array_push_back: Check for
   size_t overflow on m_size + n before passing to reserve/resize.
   On 32-bit platforms, a large n can wrap the addition to a small
   value, causing an undersized allocation followed by a heap
   buffer overflow in the subsequent memcpy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant