ossfuzz: add zip_source_zip_fuzzer for partial-window extraction paths#543
Open
tejgokani wants to merge 1 commit into
Open
ossfuzz: add zip_source_zip_fuzzer for partial-window extraction paths#543tejgokani wants to merge 1 commit into
tejgokani wants to merge 1 commit into
Conversation
The existing read harnesses (zip_read_fuzzer, zip_read_file_fuzzer,
zip_read_metadata_fuzzer) reach entry data only through
zip_fopen_index(), which always calls zip_source_zip_file_create() with
flags = 0, start = 0 and len = -1. The partial-window and raw-extraction
logic in zip_source_zip_new.c is therefore never exercised:
- start > 0 / len >= 0 sub-range reads and their offset arithmetic and
overflow / past-end-of-file checks,
- ZIP_FL_COMPRESSED (raw compressed bytes wrapped in a window),
- ZIP_FL_UNCHANGED dirent/stat selection,
- the public zip_source_zip_create() entry point.
Add a fuzz target that opens the input as an archive and, for every
entry, creates a zip_source_zip for a range of flag/start/len
combinations derived from the entry's stated size (in-range partial
ranges as well as boundary and past-the-end ranges) and drains each
source through the source interface so the window, decrypt, decompress
and crc layers run.
b127bf0 to
0c30df0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Overview
This adds a new OSS-Fuzz target,
zip_source_zip_fuzzer, that exercises thezip_source_zipwindowing and raw-extraction code inzip_source_zip_new.c,which the current read-side fuzzers do not reach.
Coverage gap
zip_read_fuzzer,zip_read_file_fuzzerandzip_read_metadata_fuzzerall readentry data through
zip_fopen_index(). That path always callszip_source_zip_file_create()withflags = 0,start = 0andlen = -1, i.e."decode the whole entry from the beginning". As a result several branches of
zip_source_zip_file_create()are never executed during fuzzing:start > 0and/orlen >= 0): the sub-range offsetarithmetic and the overflow / past-the-end-of-file checks
(
start + len < start,start + len > st.size, theZIP_INT64_MAXclamps).ZIP_FL_COMPRESSED: returning the raw compressed bytes wrapped in a windowsource instead of decompressing.
ZIP_FL_UNCHANGED: dirent/stat selection for the original on-disk entry.zip_source_zip_create()itself, the public API used to read an entry ofone archive as a source for another.
These combine caller-supplied
start/lenwith sizes parsed from the centraldirectory and then layer window → decrypt → decompress → crc sources on top, so
they are worth fuzzing directly.
What the target does
For the fuzz input interpreted as an archive, it iterates every entry and, for
each, creates a
zip_source_zipwith several flag / start / len combinationsderived from the entry's stated size:
ZIP_FL_COMPRESSEDraw window, andZIP_FL_UNCHANGED;[1, size/2], the second half,[0, size-1]);start == size,start == size + 1) todrive the rejection paths.
Each resulting source is opened and drained through the source interface so the
window, decrypt, decompress and crc layers actually run. A default password is
set so encrypted entries reach the decrypt layer.
The target builds on the existing
fuzz_main.cdriver and is registered inossfuzz/CMakeLists.txt, somake list-fuzzers(and thereforeossfuzz.sh)picks it up automatically; no change to
ossfuzz.shis required.Testing
-fsanitize=address,undefinedand no new warnings.regress/*.zipset (165 inputs) underASan + UBSan with no harness-side errors or leaks.
Checklist