VAITP Dataset

← Back to the dataset

CVE-2026-55380

Pillow: Crafted .gd file causes excessive memory allocation (DoS).

  • CVSS 7.5
  • CWE-789
  • Resource Management
  • Local

Pillow is a Python imaging library. Prior to 12.3.0, PIL/GdImageFile.py GdImageFile._open() read image dimensions from the GD 2.x header and stored them in self._size without calling Image._decompression_bomb_check(), allowing a crafted .gd file to trigger excessive C-heap allocation when loaded. This issue is fixed in version 12.3.0.

CVSS base score
7.5
Published
2026-07-06
OWASP
A04 Insecure Design
Orthogonal defect classification
Checking
Code defect classification
Missing Check
Category
Resource Management
Subcategory
Resource Exhaustion
Accessibility scope
Local
Impact
Denial of Service (DoS)
Affected component
Pillow
Fixed by upgrading
Yes

Solution

Upgrade Pillow to version 12.3.0 or later.

Vulnerable code sample

import struct
from . import Image, ImageFile

class GdImageFile(ImageFile.ImageFile):
    format = "GD"
    format_description = "GD library 2.x"

    def _open(self):
        header = self.fp.read(69)
        if not header.startswith(b"gd2\x00"):
            raise SyntaxError("not a GD 2.x file")

        # Vulnerable part: Read dimensions directly from the header
        # without validating them against a decompression bomb check.
        width, height = struct.unpack("<ii", header[4:12])

        # The dimensions are stored without any safety check.
        # A large width/height pair would cause a huge memory allocation later.
        self._size = width, height

        true_color = header[12]
        if true_color:
            self.mode = "RGB"
        else:
            self.mode = "P"

        self.tile = [("gd", (0, 0) + self.size, 0, (self.mode, self.fp.tell()))]

Patched code sample

import sys

# Mock base classes and exceptions for a self-contained example,
# representing the structure of the Pillow library.

class DecompressionBombError(Exception):
    """Mock exception for demonstration."""
    pass

class Image:
    """Mock base Image class."""
    # A default limit, similar to Pillow's Image.MAX_IMAGE_PIXELS
    MAX_IMAGE_PIXELS = 178956970

    def __init__(self):
        self._size = (0, 0)
        self.fp = None  # Mock file pointer

    def _decompression_bomb_check(self):
        """
        Checks if the image is a potential decompression bomb.
        This is a simplified version of the real check in Pillow.
        """
        if self._size[0] * self._size[1] > self.MAX_IMAGE_PIXELS:
            raise DecompressionBombError(
                f"Image size ({self._size[0]}x{self._size[1]}) "
                f"exceeds pixel limit of {self.MAX_IMAGE_PIXELS}"
            )

# The following class represents the fixed version of PIL/GdImageFile.py
class GdImageFile(Image):
    """
    Mock GdImageFile class demonstrating the fix for the vulnerability.
    """
    def _open(self):
        """
        This method simulates opening a .gd file and reading its header.
        """
        # Simulate reading image dimensions from a malicious file header.
        # In a real scenario, these would be read from self.fp.
        width_from_header = 65535
        height_from_header = 65535

        # The dimensions are assigned to self._size.
        self._size = width_from_header, height_from_header

        # THE FIX:
        # _decompression_bomb_check() is called immediately after setting self._size.
        # This prevents excessive memory allocation by validating the dimensions
        # before any pixel data is processed or allocated.
        self._decompression_bomb_check()

        # If the check passes, the rest of the image loading proceeds.
        self.mode = "P"

Payload

b'gd2\0\x02\x00\xff\x7f\xff\x7f\x01\x00'

Cite this entry

@misc{vaitp:cve202655380,
  title        = {{Pillow: Crafted .gd file causes excessive memory allocation (DoS).}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2026},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2026-55380},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-55380/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::