Repository navigation
Conversation
…026-29036) decode_pointer_inplace advanced the write pointer on every loop iteration but never copied passthrough bytes down, so any escape not at end of token truncated the decoded name ('/a~1b' became 'a~'). Worse, the old code wrote '/' to decoded[1] instead of decoded[0] for ~1. JSON Patch add/remove/replace then targeted wrong keys or failed, enabling silent data corruption and wrong-key deletion via crafted ~0/~1 sequences. Rewrite compacts properly: escapes collapse two bytes into one, all other bytes copied down; decoded never overtakes the read cursor. Invalid escapes still abort as before. Regression cases 16/17 in cjson-utils-tests.json. Red/green: new cases fail before (apply error 13), all 3 patch suites pass after; full ctest 21/22 (old_utils_tests fails only on the unrelated not-yet-merged DaveGamble#1109 variant, identical before/after this change).
w4ffl35
force-pushed
the
fix-cve-2026-29036
branch
from
October 27, 2026 15:06
b079c1b to
d77a516
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a wrong-key vulnerability in JSON Patch pointer decoding (CVE-2026-29036: crafted
~0/~1sequences make add/remove/replace target wrong object keys, silently corrupting data or deleting unintended keys).Root cause (two defects in
decode_pointer_inplace, cJSON_Utils.c):/a~1bdecoded toa~instead ofa/b.~1,/was written todecoded[1]instead ofdecoded[0], scrambling the byte after the escape.No out-of-bounds write (writes stay within already-read positions), but the corrupted child name is passed to detach/add, hence wrong-key effects. The read path (
compare_pointers) was already correct, which is whytest/getbehaved while add/remove/replace did not.Fix: compact properly — escapes collapse two bytes into one, every other byte copied down; invalid escapes abort exactly as before. Regression cases 16/17 added to
tests/json-patch-tests/cjson-utils-tests.json(replace and remove via/a~1bon a doc containing botha/banda~b).Evidence (fresh clone at 6d9f244 + #1119 test commit, ASan+UBSan build):
a~1b->a/1.old_utils_testscrashing on the unrelated not-yet-merged Fix: heap-use-after-free in merge_patch when target is not an object and contains patch (Variant of what #1060 fixed) #1109 variant (byte-identical crash with and without this change).a~1b->a/b,a~0b->a~b,~1->/.AI disclosure: drafted with AI assistance (Muse), red/green verified by the author; independent review welcome.