CVE-2026-54903: Oj: Integer Overflow in Oj.load 2GB String Handling
Summary
Oj.load is vulnerable to heap corruption when parsing a JSON string longer than 2 GB. An integer overflow in bufappendstring (buf.h:61) converts the string length to a large negative sizet, causing memcpy to copy an astronomically large amount of data out of bounds. This crashes the process and can corrupt adjacent heap memory.
Version
- Software: oj gem - Affected: all versions with ext/oj/buf.h and ext/oj/parse.c - Latest tested: 3.17.1 (confirmed present)
Details
ext/oj/buf.h, line 61:
c inline static void bufappendstring(Buf buf, const char s, sizet slen) { // ... memcpy(buf->tail, s, slen); // slen derived from 32-bit int that wrapped negative
In parse.c, escape sequence handling computes the remaining string length as an int:
c // parse.c:402 (readescapedstr) int slen = (int)(s - str); // ← wraps to negative when string > 2 GB bufappendstring(buf, str, (sizet)slen); // ← (sizet)(-2147483648) = 0x80000000...
ASAN report: ==399019==ERROR: AddressSanitizer: negative-size-param: (size=-2147483648) #0 asanmemcpy #1 bufappendstring /ext/oj/buf.h:61 #2 readescapedstr /ext/oj/parse.c:402 #3 readstr /ext/oj/parse.c:542 #4 ojparse2 /ext/oj/parse.c:882 #5 ojpiparse /ext/oj/parse.c:1256 #6 ojobjectparse /ext/oj/object.c:701 #7 load /ext/oj/oj.c:1259 0x7f5a26ff0801 is located 1 bytes inside of 2147483657-byte region [0x7f5a26ff0800, 0x7f5aa6ff0809)
Reproduce
ruby require 'oj' n = 1 << 31 # 2 GB json = '"' + ('A' n) + 'A"' # >2GB JSON string with a trailing escape Oj.load(json)
Other sources
Oj (Optimized JSON) is a JSON parser and Object marshaller packaged as a Ruby gem. In versions prior to 3.17.2, Oj.load is vulnerable to heap corruption when parsing a JSON string longer than 2 GB. An integer overflow in bufappendstring (buf.h:61) converts the string length to a large negative sizet, causing memcpy to copy an astronomically large amount of data out of bounds. This crashes the process and can corrupt adjacent heap memory. The issue has been fixed in version 3.17.2.
— MITRE
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
rubygems/ojto a version that resolves this vulnerability.Fixed in 3.17.3 - Upgrade
Upgrade
oj gemto a version that resolves this vulnerability.Fixed in 3.17.2
Event History
Frequently Asked Questions
What is the severity of CVE-2026-54903?
CVE-2026-54903 has a risk score of 42, indicating a moderate level of severity.
How do I fix CVE-2026-54903?
To fix CVE-2026-54903, update to the latest version of the Oj gem where this vulnerability has been addressed.
What is the impact of CVE-2026-54903?
The impact of CVE-2026-54903 includes potential heap corruption and application crashes when parsing large JSON strings.
Which versions of Oj are affected by CVE-2026-54903?
CVE-2026-54903 affects versions of the Oj gem prior to the patched release that addresses this vulnerability.
What type of vulnerability is CVE-2026-54903?
CVE-2026-54903 is classified as an integer overflow vulnerability leading to heap corruption.