Harness: zero-pad the C input so libinjection's over-reads are defined - #4
Merged
Merged
Conversation
libinjection reads a few bytes past the end of the input on some adversarial inputs: an ASan-confirmed out-of-bounds read in htmlencode_startswith, reached from libinjection_is_xss, on a URL-attribute value ending in an incomplete HTML entity. Past the buffer the bytes are indeterminate, so the C verdict is not reproducible across builds (the differential fuzzer saw "C: true" on the CI Linux build and "C: false" locally on byte-identical input). Copy the input into a zeroed, over-allocated buffer before handing it to libinjection, for both detectors, so any such read lands on defined zero bytes. The differential then compares against a stable C answer rather than stack garbage, and the memory-safe port (which never reads past the input) matches it. A dedicated test pins the input that surfaced this. Full corpus differential stays at 0. README and CHANGELOG updated, including the further char-semantics fixes the fuzzer surfaced.
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.
The differential fuzzer's XSS campaign reported a divergence (
Rust: false, C: true) that would not reproduce locally (C: false) on byte-identical input.Root cause: libinjection reads past the end of the input buffer. ASan
confirms a stack-buffer-overflow (out-of-bounds read) in
htmlencode_startswith,reached from
libinjection_is_xss, on a URL-attribute value ending in anincomplete HTML entity (e.g.
…&#X). Past the buffer the bytes areindeterminate, so C's verdict depends on the build and stack layout:
trueonthe CI Linux build,
falseon macOS. The memory-safe port reads within boundsand returns a deterministic answer.
Fix
The FFI harness now copies the input into a zeroed, over-allocated buffer before
calling libinjection (both detectors), so any over-read lands on defined zero
bytes. The differential compares against a deterministic C answer, and the fuzz
gate reports genuine parse differences rather than C reading garbage. A
dedicated test pins the input that surfaced this.
Result
false/false).found earlier (NUL handling across the scans and whitespace checks,
sp_password/collate over raw bytes, and the@-stripped variable value).The out-of-bounds read is a bug in upstream libinjection; a separate report to
that project is worthwhile.