CVE-2026-54502 — Oj: Stack Buffer Overflow in oj — CVE Details
Oj: Stack Buffer Overflow in Oj.dump via Large Indent
What Should I Do?
Address in Next Maintenance Window
Low exploitation probability (0.43%). Schedule for your next planned update.
Does your project use an affected oj version?
Paste your Gemfile.lock to check it for CVE-2026-54502 and every other known vulnerability, with CISA KEV and EPSS on each finding. Free with no signup for up to 10 packages, or up to 500 per scan with a free account, which also keeps up to 200 packages in saved projects.
Summary
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 * depth
The 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 variable
Reproduce
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.
Advisory Timeline
- First published June 19, 2026 (160 days ago).
- Last revised September 10, 2026 — 82 days after initial publication.
Remediation
Upgrade to the fixed version using your package manager.
gem install oj -v 3.17.3
After upgrading, scan your dependencies again to confirm the vulnerability is resolved.
Affected Packages (1)
Affects 1 ecosystem: RubyGems (1).
| Package | Fixed In |
|---|---|
| oj RubyGems · Affected: 0.5, 0.5.1, 0.5.2, 0.6.0 (+290 more) | 3.17.3 |
Vulnerability Classification
Common Weakness Enumeration (CWE) identifiers for this vulnerability type.
- CWE-121
CVSS Score Breakdown
What the CVSS (Common Vulnerability Scoring System) 7.5 score means for each attack dimension.
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
References
Frequently Asked Questions
- What is CVE-2026-54502?
- Oj: Stack Buffer Overflow in Oj.dump via Large Indent. This vulnerability has been assigned a severity rating of HIGH (CVSS score: 7.5/10).
- How do I check if my project is affected by CVE-2026-54502?
- CVE-2026-54502 affects oj. It has a 0.4% probability of exploitation within 30 days (EPSS score). Use GeekWala's free vulnerability scanner to check your dependencies against CVE-2026-54502 and 200,000+ other known vulnerabilities.
Severity & Exploitability
Significant impact if exploited, or exploitable with modest effort.
This is a below-median EPSS score — only 28.5% of tracked vulnerabilities score at or below it, so most tracked vulnerabilities are considered more likely to be exploited than this one.
Also Known As
Related CVEs
- CVE-2026-54899HIGH
Oj: Use-After-Free in Oj::Parser Symbol Key Cache Toggle
- CVE-2026-54896HIGH
Oj: Heap Buffer Overflow in Oj.dump Exception Serialization via Large Indent
- CVE-2026-54592HIGH
Oj: Stack Buffer Overflow in Oj::Doc#each_child via Deeply Nested Input
- CVE-2026-54903HIGH
Oj: Integer Overflow in Oj.load 2GB String Handling
- CVE-2026-54900HIGH
Oj: Negative-Size memcpy in Oj::Parser create_id Attribute Handling
- CVE-2026-54897HIGH
Oj: Use-After-Free in Oj::Doc Iterators via Reentrant Close
- CVE-2026-54902HIGH
Oj: Use-After-Free in Oj::Parser SAJ Long Key Callback
- CVE-2026-54500MEDIUM
Oj: intern.c form_attr (uninitialized stack read)