Skip to content

Reject numbers with no digits after a sign or 0x - #134

Merged
sheredom merged 1 commit into
sheredom:mainfrom
youdie006:reject-digitless-numbers
Oct 1, 2026
Merged

sheredom merged 1 commit into
sheredom:mainfrom
youdie006:reject-digitless-numbers

Conversation

@youdie006

Copy link
Copy Markdown
Contributor

json_get_number_size accepts a number with no digits in two places:

  • a - (or + with allow_leading_plus_sign) as the last byte of the input, because the "sign must be followed by a digit" check is guarded by offset < size. json_parse("-", 1) succeeds, and with simplified JSON a = 1\nb = - is written back as {"a":1,"b":-}.
  • 0x, -0x and +0x with allow_hexadecimal_numbers, because the hex loop accepts zero digits, so [0x] is read as 0. JSON5 requires at least one hex digit.

This checks offset >= size the way the decimal point check below already does, and requires one hex digit after 0x. The four new tests fail on main; 1737 pass with gcc Debug and under ASan+UBSan. I did not run clang, tcc or MSVC.

Written with AI assistance (Claude); I have reviewed the change.

A sign as the last byte of the input skipped the 'sign must be followed
by a digit' check, and the hexadecimal branch accepted 0x with no
digits.
@sheredom
sheredom merged commit 5248489 into sheredom:main Oct 1, 2026
24 checks passed
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.

2 participants