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

Published Jun 19, 2026
·
Updated

Summary

Oj.dump is vulnerable to a stack-based buffer overflow when a large :indent value is provided by the developer. fillindent in dump.h calls memset(indentstr, ' ', (sizet)opts->indent) without validating the size. When opts->indent is set to INTMAX (2,147,483,647), the (sizet) 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 fillindent(Out out, int depth) { if (0 < out->opts->indent) { sizet len = (sizet)(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 fillindent /ext/oj/dump.h:77 #2 dumparray /ext/oj/dumpcompat.c:165 #3 ojdumpobjtojsonusingparams /ext/oj/dump.c:818 #4 dumpbody /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: 2147483647)

Workaround

The develop should not use extreme indents and should not offer the option for users to dump Ruby data with unlimited indentation size.

Other sources

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. fillindent in dump.h calls memset(indentstr, ' ', (sizet)opts->indent) without validating the size. When opts->indent is set to INTMAX (2,147,483,647), the (sizet) 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.

NVD

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. fillindent in dump.h calls memset(indentstr, ' ', (sizet)opts-indent) without validating the size. When opts-indent is set to INTMAX (2,147,483,647), the (sizet) 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.

IBM

Affected Software

2 affected componentsFixes available
rubygems/oj<3.17.2
3.17.3
IBM Aspera Enterprise WebApps<=1.0.0 - 1.0.5

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade rubygems/oj to a version that resolves this vulnerability.

    Fixed in 3.17.3
  2. Upgrade

    Upgrade oj gem to a version that resolves this vulnerability.

    Fixed in 3.17.2
  3. Configuration

    In developer code, do not call Oj.dump with an extreme :indent value (e.g., INT_MAX / 2_147_483_647). Use a small, practical indent value to avoid triggering the stack-buffer-overflow when indentation is computed and used for memset.

    Oj.dump (Oj gem) indent = a small, validated integer (do not use INT_MAX / extreme values)

Event History

Jun 19, 2026
Advisory Published
via GitHub·07:35 PM
Data Sourced
via GitHub·07:35 PM
DescriptionWeaknessAffected Software
Jun 30, 2026
CVE Published
via MITRE·11:10 PM
Data Sourced
via MITRE·11:10 PM
DescriptionWeakness
Jul 1, 2026
Data Sourced
via NVD·12:16 AM
DescriptionSeverityWeakness
Sep 8, 2026
Data Sourced
via IBM·12:00 AM
DescriptionAffected Software

Parent advisories

This vulnerability appears in the following advisories.

Frequently Asked Questions

1

What is the severity of CVE-2026-54502?

CVE-2026-54502 has a risk score of 37, indicating a moderate severity level.

2

How do I fix CVE-2026-54502?

To mitigate CVE-2026-54502, developers should validate the size of the `:indent` value before using it in the `Oj.dump` method.

3

What is the nature of the vulnerability in CVE-2026-54502?

CVE-2026-54502 is a stack-based buffer overflow vulnerability caused by insufficient validation of large `:indent` values.

4

Which software is affected by CVE-2026-54502?

CVE-2026-54502 affects the Oj gem, part of the RubyGems ecosystem.

5

When was CVE-2026-54502 disclosed?

CVE-2026-54502 was published on June 19, 2026.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203