Jul 21, 2026·3 min read·4 visits
Integer overflow in Pillow image expansion leads to heap out-of-bounds write. Initial patch introduces a division-by-zero crash.
A heap out-of-bounds write vulnerability exists in Pillow prior to version 12.3.0 due to an integer overflow during image expansion calculations. The subsequent patch introduced a division-by-zero regression causing denial of service.
Pillow is a Python Imaging Library that provides image processing capabilities. The vulnerability exists within the native C extension libImaging, specifically in the image expansion and filtering code paths.\n\nAn attacker can trigger this vulnerability by providing an extremely large filter size parameter to ranking filters. This input flows from the Python layer into native C functions without sufficient prior validation.\n\nThe resulting calculation causes a signed integer overflow. This leads to severe memory corruption or application crashes.
The root cause lies in src/libImaging/Filter.c within the ImagingExpand function. When an application initializes a filter, the Python layer calculates the margin parameter using floor division.\n\nFor extremely large filter sizes, this division yields a margin value close to INT_MAX. When passed to the C library, the output dimensions are computed via addition and multiplication.\n\nSpecifically, the formula imIn->xsize + 2 * margin overflows the 32-bit signed integer limits. This mathematical wraparound results in a very small dimension value.\n\nConsequently, the library allocates an undersized destination buffer. However, the subsequent copying loop still uses the original large margin, resulting in an out-of-bounds write.
The vulnerable calculation path computes the destination buffer size based on the overflowed dimensions.\n\nc\n/* Vulnerable dimension calculation */\nint xsize = imIn->xsize + 2 * margin;\nint ysize = imIn->ysize + 2 * margin;\n\n/* Allocation of undersized buffer */\nimOut = ImagingNewDirty(imIn->mode, xsize, ysize);\n\n\nThe loop then iterates using the un-overflowed margin to copy pixels.\n\nc\n/* Out-of-bounds copy loop */\nfor (y = 0; y < margin; y++) {\n for (x = 0; x < margin; x++) {\n imOut->image[y][x] = imIn->image[...];\n }\n}\n\n\nThe patch attempted to check bounds but introduced a division-by-zero error.\n\nc\n/* Patched boundary check introducing regression */\nif (margin > INT_MAX / (margin * (int)sizeof(FLOAT32))) {\n return (Imaging)ImagingError_ValueError(\"filter size too large\");\n}\n
An attacker can exploit this flaw by submitting images or filter size parameters designed to trigger the overflow. This allows sequential overwriting of heap data with pixel values derived from the input image.\n\nControl over pixel values enables targeted heap corruption. This can lead to remote code execution in contexts where untrusted input dictates filter dimensions.\n\nAdditionally, the patch regression allows a straightforward denial of service attack. Passing a filter size of 1 translates to a margin of 0, triggering the division-by-zero trap.
Users should upgrade to Pillow version 12.3.0 or later to resolve the heap out-of-bounds write. This release contains validation checks that prevent large values from reaching the C execution layer.\n\nFor systems where upgrading is not immediately possible, strict input validation should be enforced. Applications should restrict filter size parameters to reasonable boundaries.\n\nFurthermore, the division-by-zero issue can be mitigated by ensuring that the margin parameter is non-zero before invoking the expansion functions.
| Product | Affected Versions | Fixed Version |
|---|---|---|
Pillow Pillow | < 12.3.0 | 12.3.0 |
| Attribute | Detail |
|---|---|
| CWE ID | CWE-190, CWE-787 |
| Attack Vector | Network |
| CVSS v3.1 Score | 8.2 |
| Impact | Heap Out-of-Bounds Write / Denial of Service |
| Exploit Status | PoC Available |
The Loofah Ruby gem version 2.25.0 and 2.25.1 contains an incomplete validation vulnerability in its public string-level utility Loofah::HTML5::Scrub.allowed_uri?. This helper fails to detect 'javascript:' URIs that are split by HTML5 named whitespace character references such as 	 and 
. Applications manually invoking this utility to validate links are vulnerable to stored Cross-Site Scripting (XSS), as browsers parse and remove these entities during rendering.
CVE-2026-50525 is a high-severity Denial of Service (DoS) vulnerability in the Microsoft .NET XML Cryptography stack. The vulnerability resides in the `System.Security.Cryptography.Xml` library, specifically within the `EncryptedXml` processing engine. Unauthenticated remote attackers can exploit this flaw by sending specifically crafted XML documents containing nested or recursive structures, or utilizing resource-intensive transforms. Processing such payloads leads to infinite CPU loops, stack exhaustion, or memory starvation, resulting in application termination.
An improper encoding and escaping vulnerability in the .NET SMTP client component allows network-based attackers to perform SMTP command smuggling and email spoofing by injecting control characters into email fields.
CVE-2026-50651 is a high-severity Denial of Service vulnerability in Microsoft .NET runtimes, SDKs, and Visual Studio installations. It stems from a weakness in System.Net.Http (CWE-770), where the HTTP/2 connection handling state machine fails to throttle server-initiated protocol streams and control frames. An attacker-controlled server can exploit this by returning highly fragmented or infinite control and continuation frame sequences. This forces the client to allocate memory indefinitely on the managed heap, eventually provoking an unhandled Out-of-Memory (OOM) exception and application crash.
CVE-2026-59198 is a high-severity heap out-of-bounds read vulnerability in Pillow, the Python imaging library, affecting versions from 5.2.0 up to 12.3.0. The vulnerability occurs in the TGA RLE compression path due to a calculation mismatch between the allocated packed 1-bit row buffer and the byte-level pixel stride assumption in the C-level encoder. This mismatch allows an attacker to leak up to approximately 57 KB of adjacent process heap memory directly into generated TGA image files.
A critical signed 32-bit integer overflow vulnerability was identified in Pillow (Python Imaging Library) versions prior to 12.3.0. The vulnerability resides within the native C extension library (libImaging) during coordinate and bounding box calculations in functions like ImagingPaste and ImagingFill2. Exploitation can bypass bounds and clipping safety checks, leading to a controlled heap backward underwrite and application crash.