CVE-2021-45958: Stack-based Buffer Overflow in ujson
Summary
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
- ujson · Debian:11
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.
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.
No signup required · Results in about 60 seconds
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 →
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.
For more information about this vulnerability, refer to the official advisory at https://github.com/pypa/advisory-database/blob/main/vulns/ujson/PYSEC-2022-25.yaml
Related vulnerabilities
Recent vulnerabilities recorded for ujson.