{"id":"CVE-2026-44660","aliases":["GHSA-c38f-wx89-p2xg","PYSEC-2026-2293"],"title":"UltraJSON has a Memory Leak in ujson.dump() on Write Failure","summary":"UltraJSON has a Memory Leak in ujson.dump() on Write Failure","severity":"high","cvss":7.5,"cvssVector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H","vendor":"ujson","product":"ujson","ecosystem":"pip","affected":["ujson < 5.12.1"],"patched":["ujson 5.12.1"],"published":"2026-05-12","updated":"2026-09-10","sourceUpdated":"2026-09-10T03:51:05.194201525Z","source":"OSV","sourceUrl":"https://osv.dev/vulnerability/GHSA-c38f-wx89-p2xg","references":[{"url":"https://github.com/ultrajson/ultrajson/security/advisories/GHSA-c38f-wx89-p2xg"},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-44660"},{"url":"https://github.com/ultrajson/ultrajson/commit/82af1d0ac01d09aa40c887b460d44b9d9f4bccd9"},{"url":"https://github.com/ultrajson/ultrajson"},{"url":"https://github.com/ultrajson/ultrajson/releases/tag/5.12.1"}],"tags":["osv","pip"],"epss":0.00421,"epssPercentile":0.36058,"ingestedAt":"2026-07-13T18:57:56.211Z","slug":"CVE-2026-44660","body":"## Overview\n\n### Summary\n\nWhen `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.\n\nCode that uses `ujson.dumps()` rather than `ujson.dump()` or only JSON load/decode methods is unaffected.\n\n### Details\n\n**Vulnerability Location:**\n- `src/ujson/python/objToJSON.c:913` - `objToJSONFile()` function start\n- `src/ujson/python/objToJSON.c:931` - Error return on write failure\n- `src/ujson/python/objToJSON.c:942` - Early return without cleanup\n \n**Root Cause:**\n\nThe `objToJSONFile()` function allocates a Python string object via `ujson_dumps_internal()`, calls the file's `write()` method, and returns early if `write()` raises an exception—but never calls `Py_DECREF(string)` on the early exit path.\n\n### PoC\n```python\nimport gc, tracemalloc, ujson\n\nclass BadFile:\n    def write(self, s):\n        raise RuntimeError(\"boom\")\n\nobj = {\"x\": \"A\" * 200000}\n\ndef run():\n    try:\n        ujson.dump(obj, BadFile())\n    except RuntimeError:\n        pass\n\nrun()\ntracemalloc.start()\ngc.collect()\nbase = tracemalloc.get_traced_memory()[0]\n\nfor i in range(5):\n    run()\n    gc.collect()\n    cur = tracemalloc.get_traced_memory()[0]\n    print(i, cur - base)\n```\n\n### Impact\n\nAny application that serializes data through `ujson.dump()` to an attacker-influenced file-like object that can fail can be driven into linear memory growth. An attacker can quickly use up all the memory of say a web server that sends JSON responses using `ujson.dump()` by repeatedly making requests then closing the connection mid response.\n\n### Remediation\n\nThe missing dec-refs were added in 82af1d0ac01d09aa40c887b460d44b9d9f4bccd9. We recommend upgrading to [UltraJSON 5.12.1](https://github.com/ultrajson/ultrajson/releases/tag/5.12.1).\n\n### Workarounds\n\nReplacing `ujson.dump(obj, file)` with `file.write(ujson.dumps(obj))` is equivalent (contrary to popular misconception, there are no streaming benefits to using `ujson.dump()`) and will avoid the memory leak.\n\n## Affected packages\n\n- `ujson < 5.12.1`\n\n## Remediation\n\nUpgrade to a patched release:\n\n- `ujson 5.12.1`","depth":"twilight","depthScore":41,"depthScoreParts":{"impact":41.3,"likelihood":0.1,"exploitation":0,"ransomware":0},"changes":[]}