Skip to content

common/json: fix out-of-bounds slice in the comment scanner - #108

Open
AlexandrKhromov2005 wants to merge 1 commit into
SagerNet:devfrom
AlexandrKhromov2005:fix/json-comment-scanner-oob
Open

common/json: fix out-of-bounds slice in the comment scanner#108
AlexandrKhromov2005 wants to merge 1 commit into
SagerNet:devfrom
AlexandrKhromov2005:fix/json-comment-scanner-oob

Conversation

@AlexandrKhromov2005

Copy link
Copy Markdown

common/json: fix out-of-bounds slice in the comment scanner

skipJSONString advances i by 2 on a backslash escape. When the backslash is the last byte of
the input, i is pushed past len(data) and returned unchanged; a caller then slices
data[keyStart:keyEnd] with keyEnd > len(data) and panics with slice bounds out of range.

This is reachable from any untrusted JSON parsed by the comment-aware decoder (UnmarshalExtended),
e.g. a sing-box config or rule-set. Found by fuzzing sing-box config parsing; the 12-byte input
{0000000#00000\n\ is enough to crash it.

Fix

Clamp the returned index to len(data). Adds FuzzUnmarshalExtended; existing tests pass.

skipJSONString advances i by 2 on a backslash escape; when the backslash is the
last byte of the input, i is pushed past len(data) and returned unchanged. A
caller then slices data[keyStart:keyEnd] with keyEnd > len(data), panicking with
"slice bounds out of range". This is reachable from any untrusted JSON parsed by
the comment-aware decoder (e.g. a sing-box config or rule-set), e.g. the 12-byte
input {0000000#00000\n\ crashes it.

Clamp the returned index to len(data). Add FuzzUnmarshalExtended.
@AlexandrKhromov2005
AlexandrKhromov2005 force-pushed the fix/json-comment-scanner-oob branch from efed245 to c7ae07f Compare August 8, 2026 04:11
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