{"id":"CVE-2026-54592","aliases":["CVE-2026-54592","GHSA-3m6q-jj5j-38c9"],"related":[],"kind":"vulnerability","state":"published","title":"Oj: Stack Buffer Overflow in Oj::Doc#each_child via Deeply Nested Input","summary":"Oj (Optimized JSON) is a JSON parser and Object marshaller packaged as a Ruby gem. In versions prior to 3.17.3, Oj::Doc#each_child, when invoked recursively over a deeply nested JSON document, overflows a fixed-size stack buffer and aborts the process, leading to DoS.  In a two-step chain in ext/oj/fast.c, doc_each_child increments doc->where past the where_path[MAX_STACK = 100] array with no bounds check and never restores it (the doc->where-- is missing), so calling each_child recursively from inside the yield block drives doc->where beyond the array. On the next entry  the function copies the path into the 800-byte stack-local buffer save_path[MAX_STACK]  using wlen = doc->where - doc->where_path, so when the previous recursive call left doc->where past where_path[100] the wlen exceeds MAX_STACK and  the memcpy overflows save_path on the C stack; because the Oj::Doc parser imposes no JSON nesting-depth limit (relying on a C-stack pressure check), deeply nested attacker input reaches this path. This issue has been fixed in version 3.17.3.","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.3, Oj::Doc#each_child, when invoked recursively over a deeply nested JSON document, overflows a fixed-size stack buffer and aborts the process, leading to DoS.  In a two-step chain in ext/oj/fast.c, doc_each_child increments doc->where past the where_path[MAX_STACK = 100] array with no bounds check and never restores it (the doc->where-- is missing), so calling each_child recursively from inside the yield block drives doc->where beyond the array. On the next entry  the function copies the path into the 800-byte stack-local buffer save_path[MAX_STACK]  using wlen = doc->where - doc->where_path, so when the previous recursive call left doc->where past where_path[100] the wlen exceeds MAX_STACK and  the memcpy overflows save_path on the C stack; because the Oj::Doc parser imposes no JSON nesting-depth limit (relying on a C-stack pressure check), deeply nested attacker input reaches this path. This issue has been fixed in version 3.17.3.","source":"cvelist"},{"lang":"en","text":"### Summary\n\n`Oj::Doc#each_child`, when invoked recursively over a deeply nested JSON\ndocument, overflows a fixed-size stack buffer and aborts the process. This is a\ndenial of service reachable from untrusted JSON.\n\n### Details\n\nTwo-step chain in `ext/oj/fast.c`:\n\n1. **`doc_each_child` (~line 1501)** increments `doc->where` past the\n   `where_path[MAX_STACK = 100]` array with no bounds check, and never restores\n   it (`doc->where--` is missing). Calling `each_child` recursively from inside\n   the yield block therefore drives `doc->where` beyond the array.\n\n2. **On the next entry (~line 1478)** the function copies the path into a\n   stack-local buffer:\n\n   ```c\n   Leaf  save_path[MAX_STACK];           // 800-byte stack buffer\n   size_t wlen = doc->where - doc->where_path;\n   if (0 < wlen) {\n       memcpy(save_path, doc->where_path, sizeof(Leaf) * (wlen + 1));\n   }\n   ```\n\n   When the previous recursive call left `doc->where` past `where_path[100]`,\n   `wlen` exceeds `MAX_STACK` and the `memcpy` overflows `save_path` on the C\n   stack.\n\nThe `Oj::Doc` parser imposes no JSON nesting-depth limit (it relies on a\nC-stack pressure check), so deeply nested attacker input reaches this path.\n\n### Proof of Concept\n\n```ruby\nrequire 'oj'\ndepth = 200\npayload = '[' * depth + '1' + ']' * depth\nOj::Doc.open(payload) do |doc|\n  r = lambda { doc.each_child { |_| r.call } }\n  r.call\nend\n```\n\nRecursion depth <= 99 iterates normally; depth >= 101 aborts. lldb backtrace\non the affected build (`ruby 3.3.8 / arm64-darwin24`):\n\n```\nSIGABRT\n#2 __abort\n#3 __stack_chk_fail\n#4 doc_each_child   (oj.bundle, fast.c)\n```\n\n### Impact\n\nReliable denial of service: any endpoint that calls\n`Oj::Doc.open(untrusted) { |d| d.each_child ... }` recursively can be crashed\nwith a small deeply-nested payload. On builds with a stack protector (the\ndefault, `-fstack-protector-strong`) the canary aborts the process before the\nsaved return address is used. The Step-1 heap OOB writes into `struct _doc`\nfields do occur, but are masked in practice because the Step-2 stack overflow\ncrashes first; turning them into anything beyond a crash has not been\ndemonstrated.\n\n### Patches\n\nFixed in **3.17.3**: `doc_each_child` now bounds-checks before incrementing\n`doc->where` (raising `Oj::DepthError`) and restores `doc->where` after the\nloop, matching the existing `each_leaf` pattern. Verified on the fixed build:\ndepth >= 101 raises a clean `Oj::DepthError` instead of aborting.\n\n### Credit\n\nReported by Zac Wang (@7a6163).","format":"markdown","source":"ghsa"},{"lang":"es","text":"Oj (JSON Optimizado) es un analizador JSON y un serializador de objetos empaquetado como una gema Ruby. En versiones anteriores a la 3.17.3, Oj::Doc#each_child, cuando se invoca recursivamente sobre un documento JSON profundamente anidado, desborda un búfer de pila de tamaño fijo y aborta el proceso, lo que lleva a DoS. En una cadena de dos pasos en ext/oj/fast.c, doc_each_child incrementa doc  ->  where más allá del array where_path[MAX_STACK = 100] sin verificación de límites y nunca lo restaura (falta el doc  ->  where--), por lo que llamar a each_child recursivamente desde dentro del bloque yield lleva a doc  ->  where más allá del array. En la siguiente entrada, la función copia la ruta en el búfer local de pila de 800 bytes save_path[MAX_STACK] usando wlen = doc  ->  where - doc  ->  where_path, por lo que cuando la llamada recursiva anterior dejó doc  ->  where más allá de where_path[100], el wlen excede MAX_STACK y el memcpy desborda save_path en la pila C; debido a que el analizador Oj::Doc no impone un límite de profundidad de anidamiento JSON (confiando en una verificación de presión de la pila C), la entrada del atacante profundamente anidada alcanza esta ruta. Este problema ha sido solucionado en la versión 3.17.3.","source":"nvd"}],"published":"2026-06-19T19:36:28.000Z","modified":"2026-10-25T17:10:00.197Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","score":7.5,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","score":7.5,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","score":7.5,"rating":"HIGH"}],"cwes":["CWE-125","CWE-787"],"affected":[{"ranges":[{"version":"< 3.17.3","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-3m6q-jj5j-38c9","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":"partial","date":"2026-07-01T12:35:37.238Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-54592","url":"https://www.cve.org/CVERecord?id=CVE-2026-54592","licence":"CVE Terms of Use","modified":"2026-07-01T12:35:39.923Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-3m6q-jj5j-38c9","url":"https://github.com/advisories/GHSA-3m6q-jj5j-38c9","licence":"CC-BY-4.0","modified":"2026-09-10T03:50:55.528Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-54592","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-54592","licence":"Public domain","modified":"2026-10-25T17:10:00.197Z"}],"updatedAt":"2026-11-25T22:59:26.855Z","epss":{"score":0.00328,"percentile":0.27897,"date":"2026-12-01T12:00:22.000Z"}}