Skip to content

fix: bounds-check nul sentinel in struct key escape scan (checkptr OOB) - #590

Open
momomuchu wants to merge 1 commit into
goccy:masterfrom
momomuchu:fix/decoder-oob-bitmap-key
Open

fix: bounds-check nul sentinel in struct key escape scan (checkptr OOB)#590
momomuchu wants to merge 1 commit into
goccy:masterfrom
momomuchu:fix/decoder-oob-bitmap-key

Conversation

@momomuchu

Copy link
Copy Markdown

Fixes #577 (also fixes the #575 duplicate).

decodeKeyByBitmapUint8 scans struct keys with raw unsafe.Pointer
arithmetic via char(). On a dangling backslash at the end of the
buffer (e.g. {"hAs\), decodeKeyCharByEscapedChar had no case for the
trailing nul sentinel, so it fell through to the unmatched-case
return nil, cursor, nil and handed back a cursor still pointing at
the sentinel. The caller then advances one past it, and the next
char() reads one byte past the backing allocation. Under -race
(which enables checkptr) that is a fatal, unrecoverable crash instead
of a decode error.

Handle nul as end of input and return ErrUnexpectedEndOfJSON, the
same error the surrounding key decoder already returns for other
truncated-input cases. Confirmed the checkptr crash on master before
the change and its absence after, under go test -race.

Added TestIssue577 with the reported repro plus a few more
dangling-backslash variants, in the style of TestIssue429.

decodeKeyCharByEscapedChar did not handle a dangling backslash at
the end of the buffer. It treated the trailing nul sentinel as an
unrecognized escaped char and returned a cursor past it, letting
decodeKeyByBitmapUint8's raw char() read walk one byte past the
allocation. Fatal under checkptr/-race on malformed input.

Fixes goccy#577, goccy#575
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.

checkptr crash in decodeKeyByBitmapUint8

1 participant