Pillow Morphology Zero-Width Image Crash CVE-2026-112397 Patched in v13.0.0
A flaw in Pillow versions prior to 13.0.0 allows zero-width images to trigger memory errors and crashes via morphology operations.
Key points
- CVE-2026-112397 carries a CVSS score of 8.7, rated as high severity by the National Vulnerability Database.
- The vulnerability exists in the ImageMorph.MorphOp.apply() function within the Python Pillow imaging library.
- Developers have released version 13.0.0, which patches the issue by rejecting invalid image geometries.
The Python Pillow library contains a high-severity memory access flaw that can crash applications processing specific image files. This defect, tracked as CVE-2026-112397, affects versions prior to 13.0.0 and stems from improper handling of zero-width images during morphology operations. Security teams should assess environments where Pillow processes untrusted image input, as the bug allows an attacker to force a process termination by supplying crafted PPM or PGM files. The National Vulnerability Database rates the issue at 8.7, indicating significant risk to application availability.
Root cause
The underlying issue resides in the ImageMorph.MorphOp.apply() method, which fails to validate image dimensions before performing memory operations. According to the NVD record, the native morphology routine attempts to index outrow[width - 1] without first checking if the width is zero. When an image has a width of zero, this calculation results in an invalid memory reference, accessing data before the row buffer. This out-of-bounds access is classified under CWE-787, highlighting a failure in boundary checks that leads to undefined behavior and potential process instability.
Attack path
An attacker exploits this flaw by creating a PPM or PGM image file with a width of zero. This specific geometry bypasses initial validation checks in older Pillow versions. When a vulnerable application loads this file and applies a morphology operation, the library executes the flawed indexing logic. The result is an immediate access violation that crashes the host process. This attack vector relies solely on the application’s willingness to process user-supplied image data through the Pillow library’s morphology functions.
Affected versions
- Pillow versions prior to 13.0.0 are vulnerable to this memory access flaw.
- The fix is included in Pillow version 13.0.0 and later releases.
- Applications using any pre-13.0.0 release of the Python Pillow library are exposed to this risk if they process untrusted images.
Mitigation
- Upgrade all instances of the Pillow library to version 13.0.0 or newer immediately.
- Audit applications to identify where Pillow processes images from untrusted or user-controlled sources.
- Implement input validation to reject image files with zero dimensions before passing them to the library.
- Monitor application logs for unexpected crashes or segmentation faults related to image processing tasks.
Signals worth monitoring
Teams usually detect this activity by reviewing application logs for sudden, unexplained process terminations during image handling. Check whether error messages reference memory access violations or segmentation faults specifically tied to morphology operations. Monitor for spikes in CPU usage followed by immediate service restarts, which may indicate repeated crash attempts. Verify that logging captures the file names or hashes of images processed right before a crash occurs. Look for patterns where specific file formats like PPM or PGM consistently trigger failures, suggesting targeted exploitation of geometry validation flaws.
What to do and how to stay safe: Pillow
- Scan your dependency tree to identify all projects using Pillow versions older than 13.0.0.
- Test your image processing pipelines with zero-width PPM and PGM files to verify current behavior.
- Once the vendor provides an update, schedule a maintenance window to deploy version 13.0.0.
- Review your incident response plan to ensure it covers application crashes caused by malformed input.
Step-by-step guide: Attack Surface Management: 6 Common Misreadings and Correct Views
General security guidance from the NetSec Observer newsroom. It is not confirmed advice from the organisations named in this story.
Frequently asked questions
What is the CVSS score for CVE-2026-112397?
The National Vulnerability Database assigns a CVSS score of 8.7, which is rated as high severity.
Which file formats can trigger this vulnerability?
PPM and PGM input files can create images with zero width that trigger the memory access flaw.
Is there a fix available for this issue?
Yes, the issue is fixed in Pillow version 13.0.0, which rejects the invalid geometry.




