You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(json): Phase 3 — fuzz the JSON decoder; fix two heap-overflows + a map-free leak
make fuzz-json (the agent-facing input boundary: every LLM tool-call
response / parsed HTTP body flows through sw_lang_json_decode) found two
real heap-buffer-overflows on its first run, both OOB reads on malformed
JSON:
1. _jd_parse number path: when a value was expected but the char was
unparseable, it force-advanced (*pp)++ to guarantee progress WITHOUT
checking for the NUL terminator — at end-of-input (e.g. `{"a":` then
EOF) it stepped past `\0`, and the next _jd_skip_ws read past the
buffer. Now it never steps past NUL; the enclosing array/object loops
gate on **pp and terminate.
2. _jd_parse_string escape path: a string whose last byte is a backslash
(`\` then NUL) consumed the backslash, then the switch's default case
copied the NUL and (*pp)++ stepped past the terminator. Now a
trailing backslash at EOF stops the loop.
Both are OOB READS on untrusted input — exactly the class Phase-3 fuzzing
exists to catch. The recursion-depth guards (SW_JD_MAX_DEPTH etc.) were
already correct; these were pointer-advance-past-NUL bugs.
Also fixed a latent leak surfaced while making the fuzz harness free its
output: sw_val_free's MAP case freed the key/val arrays but not the
element nodes (the tuple/list case already recursed). Now it recurses —
safe (all callers free fully-owned trees; none alias map sub-values) and
it plugs a real runtime leak anywhere maps are sw_val_free'd.
- tests/fuzz/fuzz_json.c + corpus (incl. a 5000-deep array): 20k
mutations, clean. Wired into make fuzz and the CI fuzz leg (parser /
JSON / distribution-unmarshal / HTTP, all under ASAN+UBSAN).
Verified: all 4 fuzz targets clean, test-sw + conformance, gc-stress,
lsan-gate, 28 doc programs — green.
https://claude.ai/code/session_01G7WBQwXWk9ggdbnoMDtuTW
0 commit comments