{"id":"CVE-2026-54502","aliases":["CVE-2026-54502","GHSA-3v45-f3vh-wg7m"],"related":[],"kind":"vulnerability","state":"published","title":"Oj: Stack Buffer Overflow in Oj.dump via Large Indent","summary":"Oj (Optimized JSON) is a JSON parser and Object marshaller packaged as a Ruby gem. In versions prior to 3.17.2, Oj.dump is vulnerable to a stack-based buffer overflow when a large :indent value is provided by the developer. fill_indent in dump.h calls memset(indent_str, ' ', (size_t)opts->indent) without validating the size. When opts->indent is set to INT_MAX (2,147,483,647), the (size_t) cast preserves the large value and memset writes 2 GB into the stack-allocated out buffer (4,184 bytes), corrupting the stack and crashing the process. This 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, Oj.dump is vulnerable to a stack-based buffer overflow when a large :indent value is provided by the developer. fill_indent in dump.h calls memset(indent_str, ' ', (size_t)opts->indent) without validating the size. When opts->indent is set to INT_MAX (2,147,483,647), the (size_t) cast preserves the large value and memset writes 2 GB into the stack-allocated out buffer (4,184 bytes), corrupting the stack and crashing the process. This issue has been fixed in version 3.17.2.","source":"cvelist"},{"lang":"en","text":"### Summary\n\n`Oj.dump` is vulnerable to a stack-based buffer overflow when a large `:indent` value is provided by the developer. `fill_indent` in `dump.h` calls `memset(indent_str, ' ', (size_t)opts->indent)` without validating the size. When `opts->indent` is set to `INT_MAX` (2,147,483,647), the `(size_t)` cast preserves the large value and `memset` writes 2 GB into the stack-allocated `out` buffer (4,184 bytes), corrupting the stack and crashing the process.\n\n### Version\n\n- **Software**: oj gem\n- **Affected**: all versions with `ext/oj/dump.h`\n- **Latest tested**: 3.17.1 (confirmed present)\n\n### Details\n\n`ext/oj/dump.h`, line 77:\n\n```c\nstatic void fill_indent(Out out, int depth) {\n    if (0 < out->opts->indent) {\n        size_t len = (size_t)(out->opts->indent * depth);\n        // ...\n        memset(out->buf + ..., ' ', len);  // len = 2147483647 * depth\n```\n\nThe `indent` option is accepted as a plain Ruby integer and stored as `int` without range validation. Multiplying by `depth` can produce a value larger than any stack or heap buffer.\n\nASAN report:\n```\n==69820==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fd1fc201278\nWRITE of size 2147483647 at 0x7fd1fc201278 thread T0\n    #0 memset\n    #1 fill_indent  /ext/oj/dump.h:77\n    #2 dump_array   /ext/oj/dump_compat.c:165\n    #3 oj_dump_obj_to_json_using_params  /ext/oj/dump.c:818\n    #4 dump_body    /ext/oj/oj.c:1429\n    #5 dump         /ext/oj/oj.c:1480\nAddress is in stack of thread T0 at offset 4728 in frame:\n    #0 dump /ext/oj/oj.c:1453\n  [544, 4728) 'out'  <== Memory access at offset 4728 overflows this variable\n```\n\n### Reproduce\n\n```ruby\nrequire \"oj\"\nobj = [0]\nOj.dump(obj, mode: :compat, indent: 2_147_483_647)\n```\n\n### Workaround\n\nThe develop should not use extreme indents and should not offer the option for users to dump Ruby data with unlimited indentation size.","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, Oj.dump es vulnerable a un desbordamiento de búfer basado en pila cuando el desarrollador proporciona un valor :indent grande. fill_indent en dump.h llama a memset(indent_str, ’ ’, (size_t)opts  ->  indent) sin validar el tamaño. Cuando opts  ->  indent se establece en INT_MAX (2.147.483.647), la conversión (size_t) preserva el valor grande y memset escribe 2 GB en el búfer de salida asignado en la pila (4.184 bytes), corrompiendo la pila y bloqueando el proceso. Este problema ha sido corregido en la versión 3.17.2.","source":"nvd"}],"published":"2026-06-19T19:35:27.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-121"],"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-3v45-f3vh-wg7m","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:49:45.690Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-54502","url":"https://www.cve.org/CVERecord?id=CVE-2026-54502","licence":"CVE Terms of Use","modified":"2026-07-01T15:50:28.392Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-3v45-f3vh-wg7m","url":"https://github.com/advisories/GHSA-3v45-f3vh-wg7m","licence":"CC-BY-4.0","modified":"2026-09-10T03:50:55.313Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-54502","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-54502","licence":"Public domain","modified":"2026-10-25T17:10:00.197Z"}],"updatedAt":"2026-11-25T22:59:26.855Z","epss":{"score":0.00401,"percentile":0.3644,"date":"2026-12-01T12:00:22.000Z"}}