CVE-2021-45958: Stack-based Buffer Overflow in ujson

ujson Updated 02 Oct 2025

Summary

01/01/2022
Yes i
Moderate
5.5

CVE-2021-45958: UltraJSON (aka ujson) through 5.1.0 has a stack-based buffer overflow in Buffer_AppendIndentUnchecked (called from encode). Affects ujson versions >= 4.0.2, < 5.1.0. Fixed in 5.1.0. How to fix ↓

Also tracked for

The same CVE-2021-45958 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.

Free scan

Check if this vulnerability affects your application

Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.

Check my app free

No signup required · Results in about 60 seconds

Sponsored Devnack Your last release was probably never penetration tested Manual testing by engineers who build software, not an auditor's checklist. Trusted by teams at Swift and Google Talk to Devnack

Background

ujson is a Python library that provides fast JSON encoding and decoding capabilities. It is commonly used in Python applications to handle JSON data efficiently. However, versions up to 5.1.0 of ujson are vulnerable to a stack-based buffer overflow in the Buffer_AppendIndentUnchecked function, which is called during the encoding process. This vulnerability can be exploited by providing a large amount of indentation, leading to a buffer overflow and potential code execution. The vulnerability was reported on January 1, 2022.

Vulnerability Detail

The stack-based buffer overflow vulnerability in ujson arises from improper handling of indentation during the encoding process. By supplying a large amount of indentation, an attacker can overwrite adjacent memory locations, potentially leading to arbitrary code execution. Exploitation of this vulnerability can have severe consequences, including remote code execution or denial of service.

How To Fix

Latest published version: 6.0.0 as of 23 Oct 2026

pip install --upgrade "ujson==6.0.0"

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

5.1.0

This is the first release that contains the fix.

pip install --upgrade "ujson==5.1.0"

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Workaround

As a temporary workaround, developers can limit the amount of indentation used in their JSON data to reduce the risk of triggering the buffer overflow. However, this is not a foolproof solution and should be considered a temporary measure until the library is updated.

Conclusion

The stack-based buffer overflow vulnerability in ujson can have severe consequences, including remote code execution or denial of service. It is crucial to update the library to version 5.1.0 or later to mitigate this vulnerability. For further support and assistance with vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for ujson →

Share this vulnerability

FAQ

ujson is a Python library that provides fast JSON encoding and decoding capabilities. It is commonly used in Python applications to handle JSON data efficiently.

The vulnerability allows an attacker to trigger a stack-based buffer overflow, potentially leading to arbitrary code execution or denial of service.

To fix this vulnerability, update ujson to version 5.1.0 or later using the command pip install --upgrade ujson.

A temporary workaround is to limit the amount of indentation used in JSON data. However, this is not a guaranteed solution and should be considered temporary.

Related vulnerabilities

Recent vulnerabilities recorded for ujson.

How To Fix

Latest published version: 6.0.0 as of 23 Oct 2026

pip install --upgrade "ujson==6.0.0"

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

5.1.0

This is the first release that contains the fix.

pip install --upgrade "ujson==5.1.0"

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback