# CVE-2026-54502: Oj: Stack Buffer Overflow in Oj.dump via Large Indent

> A stack buffer overflow in the Oj Ruby gem allows attackers to crash the application or potentially execute code by providing a large indent value.

- **Severity:** Medium 6.3 (`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`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 30 Jun 2026
- **Updated:** 1 Jul 2026
- **Also known as:** DEBIAN-CVE-2026-54502, GHSA-3v45-f3vh-wg7m, MINI-2cxv-gw8f-3fcm, MINI-3v85-84cm-wx44, MINI-5r28-9q5x-392r, MINI-666m-9j4r-68gx, MINI-8rpr-6vhf-mp3p, MINI-p425-rv7w-f2mg, MINI-p8vp-rhrx-qjg4, MINI-pg46-76j4-xgmx, MINI-pjcx-5jg2-4qv8, MINI-q3xv-g3f9-gwjv, UBUNTU-CVE-2026-54502

## What is CVE-2026-54502?

CVE-2026-54502 is a medium-severity memory corruption vulnerability in ohler55 oj, published on 30 Jun 2026. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

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.

Weakness: CWE-121 (Stack-based Buffer Overflow)

## Which versions are affected by CVE-2026-54502?

2 open source packages ship an affected version, including oj.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `oj` | RubyGems | All versions | 3.17.3 |
| `oj` | RubyGems | All versions | 3.17.3 |

## How do I fix CVE-2026-54502?

Upgrade oj to 3.17.3 or later.

## Is CVE-2026-54502 being exploited?

It is not confirmed as exploited in the wild, but public exploit code for CVE-2026-54502 exists.

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2026-54502 and fix it if it is affected.

What it is: CVE-2026-54502 is a medium-severity memory corruption vulnerability in ohler55 oj, published on 30 Jun 2026. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: It is not confirmed as exploited in the wild, but public exploit code for CVE-2026-54502 exists.

Affected packages and fixed versions:
- oj (RubyGems): affected all versions; fixed in 3.17.3
- oj (RubyGems): affected all versions; fixed in 3.17.3

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2026-54502/ (Markdown: https://insights.sbomify.com/CVE-2026-54502/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2026-54502
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2026-54502
- OSV: https://osv.dev/vulnerability/CVE-2026-54502

---
From sbomify Insights: https://insights.sbomify.com/CVE-2026-54502/
Summaries are generated and may contain mistakes; the official description above is the record.
