Hi, The following vulnerability was published for cjson. CVE-2026-16554[0]: | cJSON library is vulnerable to an integer overflow in the | print_string_ptr() function in cJSON.c on 32-bit platforms. The | escape_characters counter, a 32-bit size_t, can wrap around when | processing strings containing approximately 858,993,460 or more | control characters, causing the output buffer to be allocated based | on an underestimated length. When cJSON_PrintBuffered() is used with | a pre-allocated buffer, the subsequent write loop overflows the heap | allocation. An attacker supplying a crafted JSON string to an | application using cJSON on a 32-bit platform can cause a heap buffer | overflow, potentially leading to remote code execution, information | disclosure, or denial of service. Because project creator | contact attempts were unsuccessful, the vulnerability has only been | confirmed in version 1.7.19 but may also affect other versions. This probably should be reported in the upstream project as issue publicly as other issues have been responded to. The CNA claims that though contact were unsuccessful. If you fix the vulnerability please also make sure to include the CVE (Common Vulnerabilities & Exposures) id in your changelog entry. For further information see: [0] https://security-tracker.debian.org/tracker/CVE-2026-16554 https://www.cve.org/CVERecord?id=CVE-2026-16554 [1] https://cert.pl/en/posts/2026/07/CVE-2026-16554 Please adjust the affected versions in the BTS as needed. Regards, Salvatore
Hi, There is still no fix in upstream master (last commit 6d9f244, 2026-09-16), but an open PR targets this CVE: https://www.google.com/url?q=https://github.com/DaveGamble/cJSON/pull/1117&source=gmail&ust=1793765146315000&sa=E "Guard print_string_ptr counters against 32-bit overflow (CVE-2026-16554)" commit 527bbde4c66993ed0153c30ad5045a4e4e24df9a The PR author could only check the arithmetic on a 64-bit host, so I reproduced the bug on a real 32-bit (i386, gcc -m32) build. Review: the patch guards escape_characters before each ++ and += 5, then checks that input_length + escape_characters + sizeof("\"\"") cannot wrap before calling ensure(). ensure()'s own `needed > INT_MAX` check does not help here, because the wrapped size (~859 MB) is below INT_MAX. On 64-bit the new checks never trigger. Test (i386, cJSON master vs master + PR #1117): a string of 858993460 bytes of 0x01, created with cJSON_CreateStringReference() and printed with cJSON_PrintPreallocated() into an mmap'ed buffer with a PROT_NONE guard page right after it. 5 * 858993460 = 2^32 + 4, so escape_characters wraps to 4 and the output is sized as ~len + 6 bytes, while the true escaped output is 5153960762 bytes. - unpatched: SIGSEGV on the guard page, i.e. a heap/buffer overflow past the end of the output buffer - with PR #1117: cJSON_PrintPreallocated() returns false, no overflow Regression: I built all tests/*.c with the PR applied and Unity directly (no cmake on this box). 21/21 pass on x86_64 with -fsanitize=address,undefined and 21/21 pass on i386. This includes the PR's new print_string_should_print_escape_heavy_strings_exactly test. The cJSON.c hunk applies to the 1.7.19-2 source with a -5 line offset (patch -p1 --dry-run against cJSON.c from https://www.google.com/url?q=http://sources.debian.org&source=gmail&ust=1793765146315000&sa=E ). Thanks!