Reject negative lengths in WeaselJsonParser_parse #25

Merged
andrew merged 1 commits from weaselbot/weaseljson:weaselbot/issue-24 into main 2026-06-22 18:53:22 +00:00
Member

Closes #24

Closes #24
weaselbot added 1 commit 2026-06-22 06:27:34 +00:00
Reject negative lengths in WeaselJsonParser_parse
CI / pre-commit (pull_request) Successful in 1m4s
CI / build (-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, gcc-arm64, ubuntu-latest-arm64, false) (pull_request) Successful in 1m1s
CI / build (-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++, clang-amd64, ubuntu-latest-amd64, true) (pull_request) Successful in 1m39s
CI / build (-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, gcc-amd64, ubuntu-latest-amd64, false) (pull_request) Successful in 1m34s
CI / build (-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++, clang-arm64, ubuntu-latest-arm64, true) (pull_request) Successful in 51s
43e3c9904f
`Parser3::parse` previously formed `buf + len` immediately, so passing a
negative `len` from the C API caused undefined pointer arithmetic. Add an
explicit `len < 0` check that returns `WeaselJson_REJECT` (and makes the
rejected state sticky) before any `buf + len` computation.

Also document the non-negative length precondition in the public header
and add a regression test.

Closes #24
andrew merged commit 8d37b9b602 into main 2026-06-22 18:53:22 +00:00
andrew deleted branch weaselbot/issue-24 2026-06-22 18:53:22 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: weaselab/weaseljson#25