Skip to content

Fix out-of-bounds panic when an unquoted identifier is followed by U+0080 - #101

Open
nabokihms wants to merge 1 commit into
jmespath:masterfrom
nabokihms:fix-unquoted-identifier-oob
Open

nabokihms wants to merge 1 commit into
jmespath:masterfrom
nabokihms:fix-unquoted-identifier-oob

Conversation

@nabokihms

Copy link
Copy Markdown

consumeUnquotedIdentifier guards the identifierTrailingBits lookup with r > 128, but the mask is a [2]uint64 covering runes 0-127. At r == 128 the guard passes and the lookup indexes identifierTrailingBits[2]:

panic: runtime error: index out of range [2] with length 2
	github.com/jmespath/go-jmespath.(*Lexer).consumeUnquotedIdentifier
		lexer.go:389

Any expression with an unquoted identifier followed by U+0080 hits it, a\u0080 for example. Search and Compile are public, so an untrusted expression panics instead of returning a syntax error.

The guard is now r >= 128. The rune falls through to tokenize, which reports Unknown char: '\u0080', the same as every other non-ASCII rune (U+0081 and above already errored). Two cases added to lexingErrorTests.

@nabokihms

Copy link
Copy Markdown
Author

The problem was found using the svace static analyzer

consumeUnquotedIdentifier guards the identifierTrailingBits lookup with
`r > 128`, but the bit mask is a [2]uint64 covering runes 0-127. For
r == 128 (U+0080) the guard passes and the index expression evaluates to
identifierTrailingBits[2], which panics with "index out of range [2] with
length 2".

Any expression where an unquoted identifier is followed by U+0080 hits
this, for example "a\u0080". It is reachable from the public API, so
Search and Compile panic on an untrusted expression instead of returning
a syntax error.

Change the guard to `r >= 128`. After the fix the rune falls through to
tokenize, which reports "Unknown char: '\u0080'", matching the behaviour
of every other non-ASCII rune (U+0081 and above already errored).

Signed-off-by: maksim.nabokikh <max.nabokih@gmail.com>
@nabokihms
nabokihms force-pushed the fix-unquoted-identifier-oob branch from 2d71f54 to b0d431c Compare September 14, 2026 09:22
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.

1 participant