Repository navigation
Fix zip slip path traversal and integer overflow in zip arrays - #403
Open
ph4nt0mbyt3 wants to merge 1 commit into
Open
ph4nt0mbyt3 wants to merge 1 commit into
ph4nt0mbyt3 wants to merge 1 commit into
Conversation
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix two security issues in miniz's ZIP handling.
Bug 1: Zip Slip Path Traversal in
mz_zip_reader_file_statFilenames from the ZIP central directory are copied into
pStat->m_filenamewithout 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/backdooror/tmp/evil. When extracted, these write files outside the intended directory.Fix: Validate filenames in
mz_zip_reader_file_statimmediately after copying from the central directory header. Reject filenames that:/or\(absolute paths)..(directory traversal)C:(Windows absolute paths)Bug 2: Integer Overflow in
mz_zip_array_ensure_room/mz_zip_array_push_backBoth functions compute
pArray->m_size + nwithout checking forsize_toverflow. On 32-bit platforms, whenm_sizeis large andnis chosen to wrap the addition, the result is a small value. This leads to an undersized allocation, followed by a heap buffer overflow whenmemcpywritesn * m_element_sizebytes into the too-small buffer.Fix: Check that
m_size + ndoes not wrap (i.e., the sum is not less than either operand) before proceeding with the allocation.Impact