test(fuzz): NPY parser harness (+ 2 UB fixes it found) - #85
Merged
Conversation
Extend the libFuzzer scaffolding (from #84) to the NumPy .npy parser: fuzz the whole parse-and-build path (parse_npy_header -> slab_to_arrow / build_1d/2d_table) under ASan+UBSan. parse_npy_header validates the declared shape against the buffer size, so an accepted header can't drive the builders out of bounds — the harness exercises the real path. A VV_FUZZ-guarded npz::npy_fuzz_one mirrors NpzSource's shape dispatch; the 24.04 CI fuzz step now runs both fuzz_colblock and fuzz_npy. It found two undefined-behaviour bugs reachable via a crafted .npz, both fixed: - A dtype with a zero declared item size (e.g. "|b0") skipped the shape-fits check (`item_size > 0`) and read past the buffer. Pin item_size to the Arrow type's real element size (npy_element_bytes) — numpy bool is 1 byte, not Arrow's 1 bit — before the bounds check, so it can never be bypassed. - make_column loaded values via a typed pointer cast on the .npy data offset, which is not aligned to the element type — a misaligned load (UB; faults on aarch64). Read each element with memcpy. Legitimate .npz reads are unchanged (item_size == the type size for valid dtypes); the parser is clean over 1.4 M fuzz iterations. Suite 375. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This was referenced Jul 25, 2026
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.
Summary
Extends the libFuzzer scaffolding (#84) to the NumPy
.npyparser — a hand-rolled binary format with a history of audit bugs (negative/overflowing shapes, shape-vs-body). The harness fuzzes the whole parse-and-build path (parse_npy_header→slab_to_arrow/build_1d/build_2d_table) under ASan+UBSan; sinceparse_npy_headervalidates the declared shape against the buffer, an accepted header can't drive the builders out of bounds, so this is a true-positive-only fuzz of the real path.A
VV_FUZZ-guardednpz::npy_fuzz_onemirrorsNpzSource's shape dispatch; the 24.04 CI fuzz step now builds + runs bothfuzz_colblockandfuzz_npy.Bugs it found (both fixed, both crafted-
.npz-reachable)|b0gaveitem_size = 0, which skipped the shape-fits check (item_size > 0), soslab_to_arrowread past the buffer. Fixed: pinitem_sizeto the Arrow type's real element size (npy_element_bytes— numpy bool is 1 byte, not Arrow's 1 bit) before the check, so it can't be bypassed.make_columncast the.npydata offset (arbitrary alignment) toconst CType*and readp[i]— a misaligned load (UB; faults on aarch64). Fixed withmemcpy(same class as ci: ASan + UBSan sanitizer gate (+ bigWig misaligned-read fix) #80's bigWig fix).Verification
.npzreads are unchanged (item_sizealready equals the type size for valid dtypes); allnpz_*tests pass; suite 375.🤖 Generated with Claude Code