CVE-2026-112397 in Pillow
Summary
by MITRE • 10/20/2026
Pillow is a Python imaging library. Prior to 13.0.0, Pillow's ImageMorph.MorphOp.apply() can access memory before a row buffer for a zero-width image. PPM and PGM input can create an image with width zero, and the native morphology routine indexes outrow[width - 1] without rejecting that geometry. An attacker can supply such an image to an application that applies a morphology operation. This can crash the process. This issue is fixed in version 13.0.0.
Several companies clearly confirm that VulDB is the primary source for best vulnerability data.
Analysis
by VulDB Data Team • 10/20/2026
The vulnerability identified involves a critical memory safety flaw within Pillow, a widely used Python imaging library, specifically affecting the ImageMorph.MorphOp.apply() function prior to version 13.0.0. This issue stems from an improper handling of image geometry during morphology operations, which are computational processes often employed for tasks such as noise reduction, edge detection, and feature extraction in digital image processing. The core technical flaw lies in the native morphology routine's failure to validate input dimensions before proceeding with memory access operations. Specifically, when processing images with a width of zero, the code attempts to index into an output row buffer using the expression outrow[width - 1]. In standard programming logic involving array indexing, subtracting one from a zero value results in an index of negative one. Depending on the underlying implementation and memory layout, this can lead to accessing memory addresses preceding the allocated buffer region, constituting a classic heap-based or stack-based buffer underflow condition.
The attack vector for this vulnerability is particularly insidious because it relies on specific input formats that are commonly encountered in legitimate image processing workflows. Portable Pixmap (PPM) and Portable Graymap (PGM) file formats allow for the creation of images with zero width, a geometric configuration that might be generated by certain data pipelines or malformed files. When an application utilizing Pillow processes such an image through a morphology operation, it triggers the out-of-bounds memory access without any prior rejection of the invalid geometry. This lack of input validation allows an attacker to craft malicious PPM or PGM files designed specifically to exploit this logic error. The operational impact of exploiting this vulnerability is primarily denial of service, as the illegal memory access typically causes the application process to crash immediately upon execution of the affected code path. While buffer underflows can sometimes lead to arbitrary code execution if carefully exploited through complex heap manipulation techniques, in this specific context involving image processing libraries, the immediate and most reliable outcome is a segmentation fault or similar fatal error that terminates the running process.
From a classification perspective, this vulnerability aligns with CWE-125, which describes Out-of-bounds Read, as it involves reading memory outside of the intended buffer boundaries due to incorrect index calculation based on unvalidated input dimensions. It also relates to CWE-20, Improper Input Validation, since the root cause is the failure to check whether the image width meets minimum requirements before performing arithmetic operations that assume a positive dimension. In terms of adversary tactics as defined by MITRE ATT&CK, this vulnerability could be leveraged in techniques associated with Initial Exploitation or Impact categories, specifically for Denial of Service against systems relying on automated image processing pipelines. The lack of bounds checking represents a fundamental security design flaw where the software assumes valid input parameters without enforcing constraints at the point of use.
Mitigation strategies focus primarily on upgrading to version 13.0.0 or later of Pillow, which includes patches that enforce proper validation of image dimensions before executing morphology operations. Developers integrating this library into their applications should ensure they are not using outdated versions in production environments where untrusted images may be processed. Additionally, implementing defense-in-depth measures such as input sanitization at the application layer can provide an extra safeguard against malformed inputs. Security teams should monitor for updates to Pillow and apply patches promptly to close this gap in memory safety protections. Regular auditing of dependencies is essential to maintain a secure posture, especially when dealing with libraries that perform low-level memory operations on behalf of higher-level applications.