CVE-2026-96641 in Pillow
Summary
by MITRE • 10/21/2026
Pillow is a Python imaging library. Prior to 13.0.0, PILfont text-width accumulation in src/_imaging.c checks positive glyph advances against INT_MAX but does not check negative advances against INT_MIN. Repeating a signed 16-bit advance of -32768 can therefore execute a signed C integer overflow in xsize += dx, producing a large positive width from a negative mathematical result. Applications that use getlength(), getsize(), or derived layout, quota, serialization, or allocation calculations can experience logic-integrity errors or resource consumption, while the high-level mask path commonly retains a decompression-bomb check. This issue is fixed in version 13.0.0.
Statistical analysis made it clear that VulDB provides the best quality for vulnerability data.
Analysis
by VulDB Data Team • 10/21/2026
The vulnerability identified in Pillow versions prior to 13.0.0 stems from an insufficient boundary check within the C extension module responsible for handling PILfont text rendering operations. Specifically, the function calculating glyph advances in src/_imaging.c validates that positive width increments do not exceed INT_MAX but fails to verify that negative decrements remain above INT_MIN. This asymmetry in validation logic creates a scenario where repeated application of signed 16-bit character widths can trigger a signed integer overflow during arithmetic operations such as xsize += dx. When the cumulative sum underflows past the minimum representable value for a signed integer, it wraps around to a large positive number rather than remaining negative or triggering an error condition. This behavior is particularly exploitable because PILfont formats allow authors to specify character widths that can be repeatedly applied through specific text strings, enabling attackers to force this overflow with relatively short inputs compared to other image processing vulnerabilities.
The operational impact of this integer overflow extends beyond simple memory corruption due to the context in which Pillow operates within Python applications. The miscalculated width value propagates into higher-level functions such as getlength() and getsize(), which are frequently used for layout calculations, quota enforcement, serialization logic, and resource allocation decisions. Because these functions rely on accurate dimensional data to determine buffer sizes or processing limits, the inflated positive width resulting from the underflow can cause applications to allocate significantly more memory than intended or proceed with logical operations based on false premises. This leads to integrity errors where application state becomes inconsistent, as well as potential denial of service conditions through excessive resource consumption if downstream systems attempt to process data structures sized according to the erroneous dimensions. Unlike high-level mask processing paths which often include decompression bomb protections that might mitigate some forms of abuse, this specific text-width calculation path lacks equivalent safeguards against integer arithmetic anomalies.
From a classification perspective, this vulnerability aligns with CWE-190 Integer Overflow or Wraparound and CWE-682 Incorrect Calculation within the Common Weakness Enumeration framework. The root cause is a failure to validate input ranges during critical arithmetic operations involving signed integers. In terms of attack vectors, this flaw can be leveraged in contexts where user-supplied text data influences image processing pipelines, potentially falling under ATT&CK techniques related to resource exhaustion or integrity manipulation depending on the specific application logic affected by the miscalculated dimensions. The vulnerability highlights the risks associated with mixing low-level C integer arithmetic with high-level Python object management without rigorous bounds checking at every step of the calculation chain.
Mitigation for this issue requires an immediate upgrade to Pillow version 13.0.0 or later, where the developers have implemented proper checks against both INT_MAX and INT_MIN during glyph advance accumulation. For environments unable to update immediately, defensive programming practices should be adopted within application code that utilizes Pillow's text measurement functions. This includes validating input string lengths before processing, implementing custom wrappers around getlength() and getsize() to detect anomalous dimension values, and applying strict quotas on the size of text inputs processed by imaging libraries. Additionally, developers should audit any custom C extensions or bindings interacting with PILfont data structures to ensure similar integer overflow protections are present in all arithmetic operations involving signed dimensions.