fix: bounds check in Delete to prevent index out of range panic#280
fix: bounds check in Delete to prevent index out of range panic#280Yanhu007 wants to merge 1 commit intobuger:masterfrom
Conversation
|
Hi @buger and @Yanhu007 — we hit the same panic in the TestifySec Platform supply-chain stack and ended up vendoring a fork of v1.1.1 with a Two things that may help land this: Adversarial test fixtures We built a regression suite for GHSA-6g7g-w4f8-9c9x while building our fork. Drops cleanly into
The PoC from #274 ( Bounds check coverage The check at the call site fixes the specific panic in the linked stack trace, but Tag a release after merge and we can drop our fork — there are 31 dependabot alerts in our org that this resolves. Thanks for the fix. |
|
@Yanhu007 hi! {
desc: "GO-2026-4514: malformed JSON without closing brace",
json: `{"a":1`,
path: []string{"a"},
data: `{`,
}, |
Bug fixes: - Fix Delete panic on truncated JSON (PR #280 class): tokenEnd returns len(data) as sentinel when no delimiter found, Delete used it as unchecked array index causing out-of-bounds panic on inputs like {"test":1 - Fix ArrayEach callback error swallowing: callback's err parameter was always nil despite the signature declaring it. Callers checking err in their callback had dead error handling code. Now the callback receives per-element parse errors before iteration stops. Dead code removal (all verified safe by MC/DC analysis + 60 targeted tests): - Remove tautological for-true loops (ArrayEach, Unescape, ObjectEach) - Remove dead tokenEnd end==-1 guard in getType (tokenEnd never returns -1) - Remove dead r<=basicMultilingualPlaneOffset in decodeUnicodeEscape (tautology) - Remove dead data[i]=='{' block-skip in EachKey (structurally unreachable) - Remove contradictory keys[level][0]!='[' in searchKeys (outer guard already checks ==) - Remove dead e!=nil in ArrayEach o==0 branch (Get offset=0 always means error) - Remove tautological ln>0 guard in findKeyStart (proven by prior nextToken check) Formal verification (ReqProof): - 92 requirements (7 stakeholder + 85 system) covering all API families - 18 obligation classes including truncated_at_value_boundary, sentinel_value_boundary, error_propagation, and truncated_escape_sequence - 100% requirement-level MC/DC (204/204 witness rows) - 100% code-level MC/DC (203/203 decisions, 244/244 conditions) - Kind2 realizability, consistency, and vacuity verification - Z3 data property proofs and behavioral implication proofs - 340 FLIP fixtures + 21 Z3 boundary fixtures - CI integration via probelabs/proof-action@v1 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
I have applied formal verification techniques to jsonparser using reqproof.com (e.g. it now close to being bug free is as much as possible, with some math proof) - #281 It supersede this PR, appreciate your review. |
Fixes #274
Problem
Deleteaccessesdata[endOffset+tokEnd]without checking if the index is within bounds.tokenEnd()returnslen(data)when no terminator is found, soendOffset+tokEndcan exceed the slice length, causing a panic:Found by fuzzing.
Fix
Add a bounds check before accessing
data[endOffset+tokEnd]:All existing tests pass.