Oj gem CVE-2026-54502
MEDIUMSeverity by source
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/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X
Exploitation reaches Oj.dump via application input (AV:N, PR:N, UI:N) but requires the app to forward :indent unchanged, and demonstrated impact is a process crash only (A:L, C:N, I:N).
Primary rating from Vendor (https://github.com/ohler55/oj).
CVSS VectorVendor: https://github.com/ohler55/oj
Lifecycle Timeline
3DescriptionCVE.org
Summary
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.
Version
- Software: oj gem
- Affected: all versions with
ext/oj/dump.h - Latest tested: 3.17.1 (confirmed present)
Details
ext/oj/dump.h, line 77:
static void fill_indent(Out out, int depth) {
if (0 < out->opts->indent) {
size_t len = (size_t)(out->opts->indent * depth);
// ...
memset(out->buf + ..., ' ', len); // len = 2147483647 * depthThe 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.
ASAN report:
==69820==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fd1fc201278
WRITE of size 2147483647 at 0x7fd1fc201278 thread T0
#0 memset
#1 fill_indent /ext/oj/dump.h:77
#2 dump_array /ext/oj/dump_compat.c:165
#3 oj_dump_obj_to_json_using_params /ext/oj/dump.c:818
#4 dump_body /ext/oj/oj.c:1429
#5 dump /ext/oj/oj.c:1480
Address is in stack of thread T0 at offset 4728 in frame:
#0 dump /ext/oj/oj.c:1453
[544, 4728) 'out' <== Memory access at offset 4728 overflows this variableReproduce
require "oj"
obj = [0]
Oj.dump(obj, mode: :compat, indent: 2_147_483_647)Workaround
The develop should not use extreme indents and should not offer the option for users to dump Ruby data with unlimited indentation size.
AnalysisAI
Stack-based buffer overflow in the Oj Ruby JSON gem (versions prior to 3.17.3) allows a developer-controlled large :indent value passed to Oj.dump to overwrite up to 2 GB of stack memory, crashing the Ruby process. The flaw is reachable only when application code forwards an untrusted or extreme indent value into Oj.dump, and no public exploit identified at time of analysis demonstrates code execution beyond denial of service.
Technical ContextAI
Oj is a high-performance native C extension that serializes Ruby objects to JSON, distributed via RubyGems (pkg:rubygems/oj). The root cause is CWE-121 (Stack-based Buffer Overflow): in ext/oj/dump.h:77, fill_indent computes len = (size_t)(opts->indent * depth) and calls memset on a fixed-size stack buffer 'out' (4,184 bytes) without bounding opts->indent. Because the indent option is taken as a plain Ruby integer and stored in a C int without range validation, INT_MAX (2,147,483,647) survives the size_t cast and the subsequent multiplication by depth, allowing memset to write far past the stack frame allocated in dump() (oj.c:1453).
RemediationAI
Vendor-released patch: upgrade the oj gem to version 3.17.3 or later (bundle update oj, then redeploy) as published in GHSA-3v45-f3vh-wg7m (https://github.com/ohler55/oj/security/advisories/GHSA-3v45-f3vh-wg7m). If immediate patching is not possible, audit application code for any call site that forwards user-controlled values into Oj.dump's :indent option and clamp the value to a small bound (for example, reject indents greater than 64) before invoking the serializer; this preserves indented output for legitimate values while preventing the overflow, at the cost of one extra validation check per call. Avoid exposing Oj dump options directly to API consumers or configuration files that untrusted parties can influence.
Same weakness CWE-121 – Stack-based Buffer Overflow
View allSame technique Buffer Overflow
View allVendor StatusVendor
Share
External POC / Exploit Code
Leaving vuln.today
GHSA-3v45-f3vh-wg7m