{"id":"DHI-dfrz-3ysd-cuer-ynrl","summary":"### Summary","details":"### Summary\n\nEvery Pillow wheel from 11.1.0 onward bundles a libopenjp2 containing a heap-buffer-overflow **write** that is fixed upstream on master but has never appeared in an OpenJPEG release. See https://osv.dev/vulnerability/OSV-2025-219\n\nBecause the wheel bundles its own copy, a patched host OS does not help. It is reachable from `Image.open(fp); im.load()` with default settings.\n\nI am reporting it here rather than only upstream because Pillow is where the vulnerable binary actually reaches users.\n\nNote the inversion that makes this easy to miss: **OpenJPEG 2.5.2 and earlier are safe.** The bug was introduced in `954c6e3c` (2024-06-25), so keeping the dependency current is what creates the exposure.\n\n### Details\n\n## Affected wheels\n\nFrom `.github/dependencies.json` (`openjpeg`) at each tag:\n\n| Pillow | bundled OpenJPEG | status |\n|---|---|---|\n| 10.4.0 | 2.5.2 | safe |\n| 11.0.0 | 2.5.2 | safe |\n| **11.1.0, 11.2.1, 11.3.0** | **2.5.3** | **affected** |\n| **12.0.0 … 12.3.0** | **2.5.4** | **affected** |\n\nConfirmed on an installed wheel: `PIL.features.version_codec('jpg_2000')` → `2.5.4`, bundled file `pillow.libs/libopenjp2-*.so.2.5.4`. `main` still pins `2.5.4` as of 2026-10-06.\n\n## The defect\n\n`src/lib/openjp2/j2k.c`, in `opj_j2k_read_sod`:\n\n```c\nOPJ_UINT32 l_current_tile_part =\n    l_cstr_index-\u003etile_index[p_j2k-\u003em_current_tile_number].current_tpsno;\nl_cstr_index-\u003etile_index[...].tp_index[l_current_tile_part].end_header = l_current_pos;\nl_cstr_index-\u003etile_index[...].tp_index[l_current_tile_part].end_pos   =\n    l_current_pos + p_j2k-\u003em_specific_param.m_decoder.m_sot_length + 2;\n```\n\n`tp_index` is neither null-checked nor bounds-checked, and `l_current_tile_part` comes directly from the one-byte `TPsot` field of the SOT marker.\n\nThe correct guard already exists a few lines later in `opj_j2k_add_tlmarker` (j2k.c:8459), writing the **same array at the same index** behind `if (tp_index && l_current_tile_part \u003c nb_tps)`. One writer checked, its sibling not.\n\nReached by giving the codestream a *valid* TLM marker — so `tp_index` is allocated once by `opj_j2k_build_tp_index_from_tlm`, sized to the TLM entry count, and `opj_j2k_read_sot` then skips all resizing — while setting `TNsot = 0` in every SOT, which keeps the TLM \"valid\" and lets `TPsot` walk past the allocation.\n\n## Patch status\n\nFixed upstream in `91d08b11` (\"Fix heap buffer overlfow in opj_j2k_read_sod\", 2026-02-10).\n\nThe newest OpenJPEG tag is **v2.5.4 (2025-09-20)**, and `compare/v2.5.4...91d08b11` reports *ahead 6, behind 0* — the fix is **in no release, 8 months on**.\n\n## Suggested remediation\n\n1. Carry `91d08b11` as a patch in the wheel build until an OpenJPEG release includes it — three lines, identical to a guard already present in the same file.\n2. Consider asking OpenJPEG to cut a release; they have had an unreleased memory-corruption fix on master since February 2026, and every distro is shipping the vulnerable code.\n3. Your security handbook already tells applications to block EPS at the application layer. A similarly explicit note that `Image.open()` ignores filename/Content-Type and will reach any compiled-in codec unless `formats=` is passed would help downstream apps a lot.\n\n## Not a Pillow bug, but relevant: the extension allowlist most apps rely on does not apply\n\n`Image.open()` sniffs magic bytes, so a JPEG 2000 codestream in a file named `avatar.png` declared `Content-Type: image/png` reaches the JP2 decoder anyway.\n\nI verified this against a production service documenting PNG/JPEG-only uploads: it accepted and fully decoded a JP2 through exactly that path, with 16 formats reachable from one upload endpoint against 43 registered openers. That service has since fixed it by passing `formats=` and validating on the detected format rather than the client's `Content-Type`.\n\nThat is the reason a decoder-level issue like this one has much wider reach than downstream maintainers tend to assume.\n\n### Proof of concept\n\nASan build of OpenJPEG 2.5.4 interposed under a **stock Pillow 12.3.0**, running `Image.open(p); im.load()`:\n\n```\n==766332==ERROR: AddressSanitizer: heap-buffer-overflow\nWRITE of size 8\n    #0 opj_j2k_read_sod          j2k.c:5086\n    #1 opj_j2k_read_tile_header  j2k.c:9912\n    #2 opj_read_tile_header      openjpeg.c:575\n    #3 j2k_decode_entry          src/libImaging/Jpeg2KDecode.c:793\n    #4 ImagingJpeg2KDecode       src/libImaging/Jpeg2KDecode.c:949\n    #5 _decode                   src/decode.c:132\nlocated 8 bytes to the right of a 24-byte region allocated by\n    opj_j2k_build_tp_index_from_tlm j2k.c:8939\n```\n\nFrames 3–5 are Pillow's own decoder, not a synthetic harness. No non-default decoder options are involved; strict mode is on, which is Pillow's behaviour since Pillow never calls `opj_decoder_set_strict_mode`. A benign twin image runs the same path cleanly and returns a valid image, so this is the payload and not a parse failure.\n\nI have deliberately **not** attached the PoC file to this initial report. I'm happy to attach the PoC, the builder script and the RIP-control harness here on request, or hold everything until a fix is ready.\n\nNo disclosure deadline from me; I will not publish anything while this is being worked on.\n\n### Impact\n\nAny application that calls `Image.open()` / `im.load()` on an image it did not produce — the overwhelmingly common case for upload handlers, thumbnailers and preview pipelines — can be made to perform an out-of-bounds heap write by supplying one crafted file.\n\n**Floor, already certain.** On a stock non-sanitised wheel the overflow performs 245 writes walking to +5856 bytes past a 24-byte allocation, and glibc's own heap-metadata checker aborts the process (`corrupted size vs. prev_size`, `corrupted double-linked list`, SIGABRT). One file reliably kills a long-lived worker.\n\n**Ceiling, demonstrated as a primitive but not as a finished exploit.** With same-size-class objects alive on both sides — an ordinary busy heap — the walk crosses `opj_event_mgr_t`, which holds three `opj_msg_callback` function pointers, and `opj_event_msg` then calls one (event.c:136):\n\n```\nrip  0x4000    \u003c- value chosen by the attacker's file layout\nrsi  0x3ff2    \u003c- m_error_data, written by the same walk\n```\n\nShifting the codestream with a COM marker moves `rip` with it (`0x16ce` → `0x4000`), so the instruction pointer is attacker-**chosen** rather than incidentally invalid. A benign control image leaves the same groomed heap untouched.\n\nTo be explicit about what I did not do: I have **not** built a working exploit. That additionally needs remote heap grooming and an ASLR defeat, and I attempted neither. I am reporting a controlled control-flow primitive, not a finished chain. The CVSS AC:H reflects that.","modified":"2026-11-21T14:30:22.072365620Z","published":"2026-11-20T16:49:19Z","upstream":["GHSA-78g4-xqwv-q3g8"],"database_specific":{"coverage_exclusions":["legacy_package_image_owner"],"coverage":"partial"},"references":[{"type":"ADVISORY","url":"https://scout.docker.com/v/DHI-dfrz-3ysd-cuer-ynrl"},{"type":"ADVISORY","url":"https://github.com/advisories/GHSA-78g4-xqwv-q3g8"},{"type":"ADVISORY","url":"https://github.com/python-pillow/Pillow/security/advisories/GHSA-78g4-xqwv-q3g8"},{"type":"FIX","url":"https://github.com/uclouvain/openjpeg/commit/91d08b11a72764f6d199f32fa0c1b1abd4edc2ad"},{"type":"FIX","url":"https://github.com/python-pillow/Pillow/commit/d3470c327840f4c216a1610f30e7091dfd0b97c0"},{"type":"FIX","url":"https://github.com/python-pillow/Pillow/commit/5f8114c8096b181fae493543cd3837d9f9a971cc"},{"type":"WEB","url":"https://github.com/python-pillow/Pillow/releases/tag/13.0.0"}],"affected":[{"package":{"name":"datascience-notebook","ecosystem":"Docker Hardened Images:Debian:13","purl":"pkg:deb/dhi/datascience-notebook"},"versions":["2026.07.28-0","2026.07.28-1","2026.07.28-10","2026.07.28-11","2026.07.28-12","2026.07.28-13","2026.07.28-14","2026.07.28-15","2026.07.28-16","2026.07.28-17","2026.07.28-18","2026.07.28-19","2026.07.28-2","2026.07.28-20","2026.07.28-21","2026.07.28-22","2026.07.28-3","2026.07.28-4","2026.07.28-5","2026.07.28-6","2026.07.28-7","2026.07.28-8","2026.07.28-9"],"database_specific":{"owner_kind":"HSP","source":"https://github.com/docker-hardened-images/advisories/blob/main/dhi/osv/2026/DHI-dfrz-3ysd-cuer-ynrl.json"}},{"package":{"name":"litellm","ecosystem":"Docker Hardened Images:Debian:13","purl":"pkg:deb/dhi/litellm"},"versions":["1.100.0-0","1.100.1-0","1.101.0-0","1.101.0-1","1.102.0-0","1.103.0-0","1.103.0-1","1.103.2-0","1.103.3-0","1.104.1-0","1.104.2-0","1.104.3-0","1.105.1-0","1.106.0-0","1.106.0-1","1.106.0-2","1.106.0-3","1.106.0-4","1.106.0-5","1.106.0-6","1.106.0-7","1.106.0-8","1.106.0-9","1.108.0-0","1.108.0-1","1.108.1-0","1.108.1-1","1.108.3-0","1.108.3-1","1.108.4-0","1.108.4-1","1.108.4-2","1.109.0-0","1.109.1-0","1.109.1-1","1.110.0-0","1.110.0-1","1.110.1-0","1.110.2-0","1.110.2-1","1.95.0-0","1.95.0-1","1.96.0-0","1.96.2-0","1.96.2-1","1.97.0-0","1.98.0-0","1.99.0-0","1.99.1-0","1.99.1-1","1.99.1-2"],"database_specific":{"owner_kind":"HSP","source":"https://github.com/docker-hardened-images/advisories/blob/main/dhi/osv/2026/DHI-dfrz-3ysd-cuer-ynrl.json"}},{"package":{"name":"mlflow","ecosystem":"Docker Hardened Images:Debian:13","purl":"pkg:deb/dhi/mlflow"},"versions":["3.15.1-0","3.15.2-0","3.15.2-1","3.15.2-2","3.16.0-0","3.16.1-0","3.16.1-1","3.16.1-2","3.16.1-3","3.16.1-4","3.16.1-5","3.16.1-6","3.17.0-0","3.17.0-1","3.17.1-0","3.17.2-0","3.17.2-1","3.17.2-2","3.17.2-3","3.17.2-4","3.17.2-5","3.17.2-6","3.18.0-0","3.18.0-1","3.18.0-2","3.18.0-3","3.18.0-4","3.18.0-5"],"database_specific":{"owner_kind":"HSP","source":"https://github.com/docker-hardened-images/advisories/blob/main/dhi/osv/2026/DHI-dfrz-3ysd-cuer-ynrl.json"}},{"package":{"name":"netbox","ecosystem":"Docker Hardened Images:Debian:13","purl":"pkg:deb/dhi/netbox"},"versions":["4.6.10-0","4.6.10-1","4.6.7-0","4.6.8-0","4.6.8-1","4.6.8-2","4.6.8-3","4.6.9-0","4.6.9-1","4.6.9-2","4.7.1-0","4.7.1-1","4.7.1-2","4.7.1-3","4.7.1-4","4.7.1-5","4.7.1-6","4.7.2-0","4.7.2-1","4.7.2-2","4.7.2-3","4.7.2-4","4.7.3-0","4.7.3-1","4.7.3-2","4.7.3-3","4.7.3-4","4.7.4-0","4.7.4-1","4.7.4-2","4.7.4-3","4.7.4-4","4.7.4-5","4.7.4-6","4.7.5-0","4.7.5-1","4.7.5-2"],"database_specific":{"source":"https://github.com/docker-hardened-images/advisories/blob/main/dhi/osv/2026/DHI-dfrz-3ysd-cuer-ynrl.json","owner_kind":"HSP"}},{"package":{"name":"pytorch-2.11-cuda12.8-python3.11","ecosystem":"Docker Hardened Images:Debian:13","purl":"pkg:deb/dhi/pytorch-2.11-cuda12.8-python3.11"},"versions":["2.11.0-0","2.11.0-1","2.11.0-2","2.11.0-3","2.11.0-4","2.11.0-5","2.11.0-6","2.11.0-7","2.11.0-8"],"database_specific":{"owner_kind":"HSP","source":"https://github.com/docker-hardened-images/advisories/blob/main/dhi/osv/2026/DHI-dfrz-3ysd-cuer-ynrl.json"}},{"package":{"name":"pytorch-2.11-cuda12.9-python3.12","ecosystem":"Docker Hardened Images:Debian:13","purl":"pkg:deb/dhi/pytorch-2.11-cuda12.9-python3.12"},"versions":["2.11.0-0","2.11.0-1","2.11.0-2","2.11.0-3","2.11.0-4","2.11.0-5","2.11.0-6","2.11.0-7","2.11.0-8"],"database_specific":{"owner_kind":"HSP","source":"https://github.com/docker-hardened-images/advisories/blob/main/dhi/osv/2026/DHI-dfrz-3ysd-cuer-ynrl.json"}},{"package":{"name":"pytorch-2.11-cuda13.0-python3.11","ecosystem":"Docker Hardened Images:Debian:13","purl":"pkg:deb/dhi/pytorch-2.11-cuda13.0-python3.11"},"versions":["2.11.0-0","2.11.0-1","2.11.0-2","2.11.0-3","2.11.0-4","2.11.0-5","2.11.0-6","2.11.0-7","2.11.0-8"],"database_specific":{"source":"https://github.com/docker-hardened-images/advisories/blob/main/dhi/osv/2026/DHI-dfrz-3ysd-cuer-ynrl.json","owner_kind":"HSP"}},{"package":{"name":"pytorch-2.13-cuda12.6-python3.11","ecosystem":"Docker Hardened Images:Debian:13","purl":"pkg:deb/dhi/pytorch-2.13-cuda12.6-python3.11"},"versions":["2.13.0-0","2.13.0-1","2.13.0-2","2.13.0-3","2.13.0-4","2.13.0-5","2.13.0-6","2.13.0-7","2.13.0-8"],"database_specific":{"owner_kind":"HSP","source":"https://github.com/docker-hardened-images/advisories/blob/main/dhi/osv/2026/DHI-dfrz-3ysd-cuer-ynrl.json"}},{"package":{"name":"pytorch-2.13-cuda13.0-python3.12","ecosystem":"Docker Hardened Images:Debian:13","purl":"pkg:deb/dhi/pytorch-2.13-cuda13.0-python3.12"},"versions":["2.13.0-0","2.13.0-1","2.13.0-2","2.13.0-3","2.13.0-4","2.13.0-5","2.13.0-6","2.13.0-7","2.13.0-8"],"database_specific":{"owner_kind":"HSP","source":"https://github.com/docker-hardened-images/advisories/blob/main/dhi/osv/2026/DHI-dfrz-3ysd-cuer-ynrl.json"}},{"package":{"name":"pytorch-2.7-cuda12.8-python3.12","ecosystem":"Docker Hardened Images:Debian:13","purl":"pkg:deb/dhi/pytorch-2.7-cuda12.8-python3.12"},"versions":["2.7.0-0","2.7.0-1","2.7.0-2","2.7.0-3","2.7.0-4","2.7.0-5","2.7.0-6","2.7.0-7","2.7.0-8"],"database_specific":{"owner_kind":"HSP","source":"https://github.com/docker-hardened-images/advisories/blob/main/dhi/osv/2026/DHI-dfrz-3ysd-cuer-ynrl.json"}},{"package":{"name":"pytorch-2.9-cuda12.9-python3.12","ecosystem":"Docker Hardened Images:Debian:13","purl":"pkg:deb/dhi/pytorch-2.9-cuda12.9-python3.12"},"versions":["2.9.1-0","2.9.1-1","2.9.1-2","2.9.1-3","2.9.1-4","2.9.1-5","2.9.1-6","2.9.1-7","2.9.1-8"],"database_specific":{"owner_kind":"HSP","source":"https://github.com/docker-hardened-images/advisories/blob/main/dhi/osv/2026/DHI-dfrz-3ysd-cuer-ynrl.json"}},{"package":{"name":"superset","ecosystem":"Docker Hardened Images:Debian:13","purl":"pkg:deb/dhi/superset"},"versions":["6.1.0-0","6.1.0-1","6.1.0-10","6.1.0-11","6.1.0-12","6.1.0-13","6.1.0-14","6.1.0-15","6.1.0-16","6.1.0-17","6.1.0-18","6.1.0-19","6.1.0-2","6.1.0-20","6.1.0-21","6.1.0-22","6.1.0-23","6.1.0-24","6.1.0-25","6.1.0-26","6.1.0-27","6.1.0-28","6.1.0-29","6.1.0-3","6.1.0-30","6.1.0-31","6.1.0-32","6.1.0-33","6.1.0-34","6.1.0-35","6.1.0-36","6.1.0-37","6.1.0-38","6.1.0-39","6.1.0-4","6.1.0-40","6.1.0-41","6.1.0-42","6.1.0-5","6.1.0-6","6.1.0-7","6.1.0-8","6.1.0-9"],"database_specific":{"owner_kind":"HSP","source":"https://github.com/docker-hardened-images/advisories/blob/main/dhi/osv/2026/DHI-dfrz-3ysd-cuer-ynrl.json"}}],"schema_version":"1.9.2","severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H"}]}