fix: guard Delete against out-of-range endOffset+tokEnd on fuzz input#282
Open
SAY-5 wants to merge 1 commit intobuger:masterfrom
Open
fix: guard Delete against out-of-range endOffset+tokEnd on fuzz input#282SAY-5 wants to merge 1 commit intobuger:masterfrom
SAY-5 wants to merge 1 commit intobuger:masterfrom
Conversation
Delete's nested-key branch assumed that endOffset+tokEnd (the byte after the found value's closing token) always stayed inside the input buffer. Fuzz-generated or truncated input can leave the computed index one-past the buffer, and the subsequent data[endOffset+tokEnd] read panicked with 'index out of range', killing the whole process before any caller could recover - this is how Delete surfaced as a deadly signal under libFuzzer (buger#274). Bail out early and return the original buffer unchanged when the next-byte index is out of range. That is equivalent to 'there is nothing after the match to remove', which is the correct no-op semantic here: the caller gets their input back, no panic, no partial delete. Closes buger#274 Signed-off-by: SAY-5 <SAY-5@users.noreply.github.com>
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.
What
Fixes #274.
Delete's nested-key branch assumed thatendOffset+tokEnd(the byte after the found value's closing token) always stayed inside the input buffer. Fuzz-generated or truncated input can leave the computed index one-past the buffer, and the subsequentdata[endOffset+tokEnd]read panics with:killing the whole process before any caller could recover - this is how Delete surfaces as a deadly signal under libFuzzer / oss-fuzz.
Fix
Bail out early and return the original buffer unchanged when the next-byte index is out of range. That matches the correct no-op semantic: 'there is nothing after the match to remove', so the caller gets their input back, no panic, no partial delete. The happy path is unchanged.
Verification
Locally on macOS, go 1.26.2:
gofmt -s -l parser.go: cleango vet ./...: clean (the existingbytes_unsafe_test.go:26 reflect.StringHeadernote is pre-existing and untouched by this PR)go test -race -count=1 ./...: passCloses #274