Skip to content

fix(internal): bounds-check skipWhiteSpace to prevent OOB read - #595

Closed
AruneshDwivedi wants to merge 1 commit into
goccy:masterfrom
AruneshDwivedi:master
Closed

fix(internal): bounds-check skipWhiteSpace to prevent OOB read#595
AruneshDwivedi wants to merge 1 commit into
goccy:masterfrom
AruneshDwivedi:master

Conversation

@AruneshDwivedi

Copy link
Copy Markdown

The skipWhiteSpace function in both encoder and decoder loops over
buffer bytes without checking the cursor is within bounds.

When JSON input contains only whitespace or reaches a buffer boundary,
the loop increments past len(buf) causing an index out of range panic.

Fixed by adding cursor < int64(len(buf)) guard before array access
in both encoding path (internal/encoder/compact.go) and decoding path
(internal/decoder/context.go).

This matches the same pattern already used in the StreamDecoder variant
at internal/decoder/stream.go line 238.

The skipWhiteSpace function in both encoder and decoder loops over
buffer bytes without checking the cursor is within bounds. When JSON
input contains only whitespace or reaches a buffer boundary, the loop
increments past len(buf) causing an index out of range panic.

Fixed by adding 'cursor < int64(len(buf))' guard before array access
in both encoding path (internal/encoder/compact.go) and decoding path
(internal/decoder/context.go).

Signed-off-by: Kushal Dwivedi <arunesh.devops@gmail.com>
@AruneshDwivedi AruneshDwivedi closed this by deleting the head repository Aug 1, 2026
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