High

Pillow: Out-of-bounds access in _imagingmorph on a zero-width image

  • Disclosed: 20.10.2026
  • Updated: 20.10.2026 23:29

Summary

A PPM or PGM file can declare a width of 0, which Pillow accepts, producing an image of size (0, N). Passing that image to ImageMorph.MorphOp.apply() makes the native morphology code index a row buffer at outrow[width - 1], which is outrow[-1] when the width is 0. The process crashes.

Details

The PPM parser reads width and height with no lower-bound check:

  • src/PIL/PpmImagePlugin.py:119

The native apply() writes the row edges with no guard that the width is positive:

  • src/_imagingmorph.c:81 sets outrow[0] = outrow[width - 1] = 0;

match() and get_on_pixels() use the same edge-indexing pattern.

PoC

python
from PIL import Image, ImageMorph

# A width-0 image (also producible from a crafted PPM header). apply() indexes
# outrow[width - 1] == outrow[-1] in native code.
im = Image.new("L", (0, 5))
ImageMorph.MorphOp(op_name="dilation4").apply(im)

Run it:

bash
$ python 03_poc.py
Segmentation fault (core dumped)

Observed on a source build of commit 3e2ab96.

Under AddressSanitizer:

==ERROR: AddressSanitizer: SEGV on unknown address (pc ... in apply)
    #0 apply   src/_imagingmorph.c:81
SUMMARY: AddressSanitizer: SEGV src/_imagingmorph.c:81 in apply

With width 0 the outrow[width - 1] write lands on an unmapped page, so it surfaces as a SEGV pinned to the edge-write line rather than a redzone overflow.

Impact

Out-of-bounds write in a C extension. Affects any application that runs a morphology operation on an image opened from untrusted input. Result is a crash and possible memory corruption.

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 -
CVSS vector
CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N
Weakness (CWE)
CWE-787
Platform
Python (PyPI)
Package
pillow
Disclosed
20.10.2026
Updated
20.10.2026 23:29

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

OSV / GitHub Advisory Database - GHSA-58r4-6rv3-gfh8 - 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 (81) in the archive
Total entries
81
First → latest
04.2014 10.2026
Without a fix
0
Exploited in attacks
1

Severity breakdown

  • Critical 10
  • High 53
  • Medium 16
  • Low 1
  • Unrated 1

Disclosures per year

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

earlier: 12

Severity:
  1. Pillow: Out-of-bounds access in _imagingmorph on a zero-width image this entry
    High CVE-2026-112397 < 13.0.0 13.0.0
  2. High · 7.5 CVE-2026-59200 >= 5.1.0, < 12.3.0 12.3.0
  3. High CVE-2026-42311 >= 10.3.0, < 12.2.0 12.2.0
  4. High · 7.5 CVE-2026-40192 >= 10.3.0, < 12.2.0 12.2.0
  5. High CVE-2026-25990 >= 10.3.0, < 12.1.1 12.1.1
  6. High · 7.1 CVE-2025-48379 >= 11.2.0, < 11.3.0 11.3.0
  7. High · 6.7 CVE-2024-28219 < 10.3.0 10.3.0
  8. Critical · 8.1 CVE-2023-50447 < 10.2.0 10.2.0
  9. High · 8.8 Exploited in attacks CVE-2023-4863 < 10.0.1 10.0.1
  10. High · 7.5 CVE-2022-45199 >= 9.2.0, < 9.3.0 9.3.0
  11. High · 7.5 CVE-2022-30595 >= 9.1.0, < 9.1.1 9.1.1
  12. High · 9.1 CVE-2022-24303 < 9.0.1 9.0.1
  13. Critical · 9.8 CVE-2022-22817 < 9.0.1 9.0.1
  14. High · 7.5 CVE-2021-23437 >= 5.2.0, < 8.3.2 8.3.2
  15. Critical · 9.8 CVE-2021-34552 < 8.3.0 8.3.0
  16. High · 7.5 CVE-2021-28677 < 8.2.0 8.2.0
  17. High · 7.5 CVE-2021-28676 < 8.2.0 8.2.0
  18. High · 9.1 CVE-2021-25288 >= 2.4.0, < 8.2.0 8.2.0
  19. High · 9.1 CVE-2021-25287 >= 2.4.0, < 8.2.0 8.2.0
  20. High · 5.5 CVE-2021-28675 < 8.2.0 8.2.0
  21. High · 7.5 CVE-2021-25293 >= 4.3.0, < 8.1.1 8.1.1
  22. High · 7.5 CVE-2021-25291 < 8.2.0 8.2.0
  23. High · 7.5 CVE-2021-25290 < 8.1.1 8.1.1
  24. Critical · 9.8 CVE-2021-25289 < 8.1.1 8.1.1
  25. High · 7.5 CVE-2021-27923 < 8.1.2 8.1.2
  26. High · 7.5 CVE-2021-27922 < 8.1.2 8.1.2
  27. High · 7.5 CVE-2021-27921 < 8.1.2 8.1.2
Show more (20) Showing 40 of 63

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.