CVE-2026-54502: Oj Stack Buffer Overflow Vulnerability

HIGH
Advisory Identifier: GHSA-3v45-f3vh-wg7m
CWE-121
Published
Advisory Summary

CVE-2026-54502 is a HIGH stack buffer overflow vulnerability (CWE-121: Stack-based Buffer Overflow) affecting Oj libraries in the RubyGems ecosystem. The issue involves stack buffer overflow in oj.dump via large indent. Remediation is available by upgrading affected packages to version 3.17.3.

CVE-2026-54502 at a Glance

CVE Identifier CVE-2026-54502
GHSA Identifier GHSA-3v45-f3vh-wg7m
Severity HIGH
CVSS v3.1 Base Score N/A
CWE Classification CWE-121: Stack-based Buffer Overflow
Affected Product Oj
Package Ecosystem RubyGems
Published Date
Last Updated

How to Fix CVE-2026-54502

To remediate this vulnerability, upgrade all affected Oj dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

oj fixed: 3.17.3
Upgrade oj to 3.17.3
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for oj

How to Check if You Are Affected

To determine whether your application is affected by CVE-2026-54502, inspect your project dependencies for Oj:

inspect dependencies for oj

Analyze the terminal output to locate any version of Oj in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 3.17.3), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-121: Stack-based Buffer Overflow, where a stack-based buffer overflow condition is a condition where the buffer being overwritten is allocated on the stack (i.e., is a local variable or, rarely, a parameter to a function). In Oj, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### 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: ```c 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 ```ruby 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.

CVE-2026-54502 Affected Oj Versions

1 component(s)
Fixed Versions:
3.17.3
Product / Package Ecosystem Affected Versions Fixed Version
oj
RubyGems
< 3.17.3
3.17.3

References

Frequently Asked Questions

What is CVE-2026-54502?
CVE-2026-54502 is a security vulnerability in Oj involving Stack Buffer Overflow in Oj.dump via Large Indent under CWE-121: Stack-based Buffer Overflow.
Which Oj versions are affected?
Affected versions include releases prior to 3.17.3 across affected packages: oj.
What version fixes CVE-2026-54502?
Upgrading to 3.17.3 (or the latest patched release for your respective branch) resolves the vulnerability.
Is oj affected?
Yes, oj is affected in releases prior to 3.17.3. Upgrade your dependency to 3.17.3 or later.
What CWE is associated with CVE-2026-54502?
CVE-2026-54502 is classified under CWE-121: Stack-based Buffer Overflow (A stack-based buffer overflow condition is a condition where the buffer being overwritten is allocated on the stack (i.e., is a local variable or, rarely, a parameter to a function).).
How can I check RubyGems dependencies for CVE-2026-54502?
Run the dependency tree command: 'inspect dependencies for oj'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-3v45-f3vh-wg7m",
  "modified" : "2026-06-19T19:35:27Z",
  "published" : "2026-06-19T19:35:27Z",
  "aliases" : [ "CVE-2026-54502" ],
  "summary" : "Oj: Stack Buffer Overflow in Oj.dump via Large Indent",
  "details" : "### 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.",
  "severity" : [ {
    "type" : "CVSS_V4",
    "score" : "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"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "RubyGems",
      "name" : "oj"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "3.17.3"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "< 3.17.2"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/ohler55/oj/security/advisories/GHSA-3v45-f3vh-wg7m"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/ohler55/oj"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-121" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-06-19T19:35:27Z",
    "nvd_published_at" : null
  }
}