Skip to content

fix: bounds check in Delete to prevent index out of range panic#280

Open
Yanhu007 wants to merge 1 commit intobuger:masterfrom
Yanhu007:fix/delete-bounds-check
Open

fix: bounds check in Delete to prevent index out of range panic#280
Yanhu007 wants to merge 1 commit intobuger:masterfrom
Yanhu007:fix/delete-bounds-check

Conversation

@Yanhu007
Copy link
Copy Markdown

Fixes #274

Problem

Delete accesses data[endOffset+tokEnd] without checking if the index is within bounds. tokenEnd() returns len(data) when no terminator is found, so endOffset+tokEnd can exceed the slice length, causing a panic:

panic: runtime error: index out of range [9] with length 9

Found by fuzzing.

Fix

Add a bounds check before accessing data[endOffset+tokEnd]:

if endOffset+tokEnd >= len(data) {
    return data
}

All existing tests pass.

Delete accesses data[endOffset+tokEnd] without checking if the
index is within bounds. When tokenEnd returns len(data) (no
terminator found), this causes an index out of range panic.

Found by fuzzing (issue buger#274).

Fixes buger#274
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Oob (index out of range)

1 participant