Skip to content

Upgrading ujson 4 to 5

Breaking4.3.0 → 5.13.0Breaking2Security9Platform8New9Changed13Fixed22Other14

BreakingUpgrade verdict

2 breaking changes and 8 platform requirement changes and 9 security fixes.

  • If a custom object's toDict() method returns something that is not a dictionary, ujson now raises an error instead of quietly producing null.
  • When a dictionary has True or False as keys, ujson now writes them as lowercase "true" and "false" strings.
  • The package can now be installed and used on Python 3.15.
  • This version no longer supports Python 3.9, so users on that version must upgrade Python.
Top 5 of 19 that need code or config changes

Python requirement changed in 5.12.0: >=3.6 → >=3.10.

Breaking2
Raises TypeError if toDict() returns a non-dict instead of silently converting it to null.
toDict()
Uses lowercase strings for bool dict keys.
Security9
UltraJSON is a fast JSON encoder and decoder written in pure C with bindings for Python 3.7+. Prior to 5.13.0, ujson.dumps() (or ujson.dump() or ujson.encode()) have a reject_bytes=False option. When set, they may accept malformed or truncated UTF-8 byte sequences, silently rewriting them into different Unicode characters instead of rejecting them. This leads to input validation bypass and data integrity issues. This vulnerability is fixed in 5.13.0.
Medium · CVSS 6.5
UltraJSON is a fast JSON encoder and decoder written in pure C with bindings for Python 3.7+. Prior to 5.12.1, when ujson.dump() writes to a file-like object and the write operation raises an exception, the serialized JSON string object is not decremented, leaking memory. Each failed write operation leaks the full size of the serialized payload. This vulnerability is fixed in 5.12.1.
High · CVSS 7.5
UltraJSON is a fast JSON encoder and decoder written in pure C with bindings for Python 3.7+. Versions 5.4.0 through 5.11.0 contain an accumulating memory leak in JSON parsing large (outside of the range [-2^63, 2^64 - 1]) integers. The leaked memory is a copy of the string form of the integer plus an additional NULL byte. The leak occurs irrespective of whether the integer parses successfully or is rejected due to having more than sys.get_int_max_str_digits() digits, meaning that any sized leak per malicious JSON can be achieved provided that there is no limit on the overall size of the payload. Any service that calls ujson.load()/ujson.loads()/ujson.decode() on untrusted inputs is affected and vulnerable to denial of service attacks. This issue has been fixed in version 5.12.0.
High · CVSS 7.5
UltraJSON is a fast JSON encoder and decoder written in pure C with bindings for Python 3.7+. Versions 5.10 through 5.11.0 are vulnerable to buffer overflow or infinite loop through large indent handling. ujson.dumps() crashes the Python interpreter (segmentation fault) when the product of the indent parameter and the nested depth of the input exceeds INT32_MAX. It can also get stuck in an infinite loop if the indent is a large negative number. Both are caused by an integer overflow/underflow whilst calculating how much memory to reserve for indentation. And both can be used to achieve denial of service. To be vulnerable, a service must call ujson.dump()/ujson.dumps()/ujson.encode() whilst giving untrusted users control over the indent parameter and not restrict that indentation to reasonably small non-negative values. A service may also be vulnerable to the infinite loop if it uses a fixed negative indent. An underflow always occurs for any negative indent when the input data is at least one level nested but, for small negative indents, the underflow is usually accidentally rectified by another overflow. This issue has been fixed in version 5.12.0.
High · CVSS 7.5
Fixes CVE-2022-31116 by replacing the wchar_t string decoding implementation with a uint32_t-based one.
wchar_tuint32_tHigh · CVSS 7.5
Fixes CVE-2022-31116 by correcting handling of surrogates on decoding.
High · CVSS 7.5
Fixes CVE-2022-31117, a potential double free of the buffer during string decoding.
Medium · CVSS 5.9
Fixes buffer overflows (CVE-2021-45958).
UltraJSON (aka ujson) through 5.1.0 has a stack-based buffer overflow in Buffer_AppendIndentUnchecked (called from encode). Exploitation can, for example, use a large amount of indentation.
Platform8
Adds support for Python 3.15.
Drops support for Python 3.9.
Adds support for Python 3.14.
Drops support for end-of-life Python 3.8.
Adds support for Python 3.13.
Drops support for Python 3.7.
Adds support for Python 3.11 and PyPy3.9.
Drops support for Python 3.6, which is nearing end of life.