fix: prevent slice bounds panic in Row.matchAll#69
Open
Yanhu007 wants to merge 1 commit into
Open
Conversation
Row.matchAll could panic with "slice bounds out of range" when
matching against certain malformed glob patterns like "/{a{*.json{".
The computed end index (idx + next + 1) could exceed the string
length.
Add explicit bounds checks: return false early if the string has
fewer runes than needed or if the computed slice end exceeds the
string length.
Fixes gobwas#59
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.
Fixes #59
Problem
Row.matchAllpanics withslice bounds out of rangefor certain glob patterns:The computed slice end
idx + next + 1can exceed the string length when the pattern produces aRowwithRunesLengthlarger than the actual string being matched.Fix
Add explicit bounds checks before slicing:
falseearly if fewer runes are available than neededfalseif the computed end index exceeds string lengthAll existing tests pass, plus the reproducer from the issue now returns
falseinstead of panicking.