CVEReports
CVEReports

Automated vulnerability intelligence platform. Comprehensive reports for high-severity CVEs generated by AI.

Product

  • Home
  • Sitemap
  • RSS Feed

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 CVEReports. All rights reserved.

Made with love by Amit Schendel & Alon Barad



CVE-2026-59204

CVE-2026-59204: Denial of Service via Memory Exhaustion in Pillow JPEG2000 Decoder

Amit Schendel
Amit Schendel
Senior Security Researcher

Jul 21, 2026·7 min read·10 visits

Executive Summary (TL;DR)

A state accumulation bug in Pillow's JPEG2000 tile decoder allows unauthenticated attackers to crash applications via Out-of-Memory termination using crafted multi-tiled images.

A Denial of Service vulnerability exists in the JPEG2000 decoder of Pillow (versions 8.2.0 to 12.2.0) due to memory allocation state accumulation across tiles, leading to rapid process termination.

Vulnerability Overview

The Pillow imaging library includes native C implementations for processing specialized image formats, including the JPEG2000 standard. The JPEG2000 decoder relies on the open-source OpenJPEG library to handle the compressed codestream, passing decoded pixels to a Pillow-specific memory buffer for structural reorganization. Within this subsystem, a security flaw was discovered in the tiled decompressor logic that permits unauthenticated remote attackers to trigger resource exhaustion.

The vulnerability is classified under CWE-789 (Memory Allocation with Excessive Size Value) and CWE-770 (Allocation of Resources Without Limits or Throttling). It exists because the decoder retains and accumulates state variables across independent decoding operations. Consequently, processing multi-tiled JPEG2000 images leads to exponential memory overhead relative to the dimensions of the file.

This technical analysis details the memory-management flaw within Pillow's decoding routine, walks through the C code patch, and outlines defensive mechanisms to prevent process crash attacks. The flaw affects Pillow versions from 8.2.0 through 12.2.0 and has been resolved in version 12.3.0.

Root Cause Analysis

To understand the mechanics of the vulnerability, it is necessary to examine how the JPEG2000 standard utilizes image tiling. Tiling divides an image into discrete, independent rectangular segments that can be decoded sequentially, minimizing the overall memory requirements for systems processing large images. Pillow handles this logic within the j2k_decode_entry function inside the src/libImaging/Jpeg2KDecode.c source file.

During the decoding sequence, the function loops through each individual tile, extracting metadata and allocating a transient scratch buffer to store the raw decompressed pixel bytes. To size this scratch buffer, the engine calculates the required byte allocation using the dimensions of the active tile and the width of its cumulative component channels. This width tracking is managed by the integer variable total_component_width.

In vulnerable versions, the decoder initializes total_component_width to zero outside the loop that iterates over each image tile. As the decoder moves from one tile to the next, it fails to reset this variable. Instead, the decoder continually adds the component widths of subsequent tiles to the running total.

When the decoder invokes realloc on the state scratch buffer to accommodate the newly computed dimensions, the memory requirement balloons far beyond the system's actual capacity. For images configured with hundreds or thousands of tiny tiles, this accumulation behavior rapidly scales the allocation request into gigabytes. The operating system encounters an Out-of-Memory (OOM) condition and terminates the parent Python process, resulting in a denial of service.

Code Analysis & Memory Allocation Flow

The vulnerability resides in src/libImaging/Jpeg2KDecode.c. Below is an annotated visual comparison of the vulnerable decoding structure versus the remediated code path.

/* VULNERABLE CODE - src/libImaging/Jpeg2KDecode.c */
j2k_decode_entry(Imaging im, ImagingCodecState state) {
    size_t tile_bytes = 0;
    unsigned n, tile_height, tile_width;
    int total_component_width = 0; // Vulnerability: Declared outside the loop scope
 
    stream = opj_stream_create(BUFFER_SIZE, OPJ_TRUE);
 
    // Loop iterating over each tile in the JPEG2000 codestream
    for (/* tile loop */) {
        // total_component_width is NOT reset to 0 here
 
        for (n = 0; n < tile_info.nb_comps; n++) {
            int csize = (image->comps[n].prec + 7) >> 3;
            // Accumulation bug: Adds to the value from previous iterations
            total_component_width += csize * image->comps[n].w;
        }
 
        // Formula generates progressively larger sizes
        tile_bytes = total_component_width * tile_height * tile_width;
 
        // Allocation size exceeds physical memory bounds
        state->buffer = realloc(state->buffer, tile_bytes);
    }
}

The patch merged in Git commit 13ada41172142f2fd9f0906f615a00ea623a11ca resolves this state accumulation by shifting the declaration of total_component_width to local scope within the loop.

/* PATCHED CODE - src/libImaging/Jpeg2KDecode.c */
j2k_decode_entry(Imaging im, ImagingCodecState state) {
    size_t tile_bytes = 0;
    unsigned n, tile_height, tile_width;
    // total_component_width removed from this outer scope
 
    stream = opj_stream_create(BUFFER_SIZE, OPJ_TRUE);
 
    for (/* tile loop */) {
        // Fix: re-initialized to 0 on every loop iteration
        int total_component_width = 0;
 
        for (n = 0; n < tile_info.nb_comps; n++) {
            int csize = (image->comps[n].prec + 7) >> 3;
            // Accumulation is restricted to the components of the current tile
            total_component_width += csize * image->comps[n].w;
        }
 
        // Calculation accurately reflects only the active tile
        tile_bytes = total_component_width * tile_height * tile_width;
 
        // realloc scales within correct boundaries
        state->buffer = realloc(state->buffer, tile_bytes);
    }
}

While this patch effectively isolates tile calculations, security engineers must note that state->buffer is resized upward via realloc() but is never resized downward. If an image begins with an extremely large tile followed by numerous small tiles, the peak memory allocation remains allocated on the heap for the duration of the decoding cycle. This behavior can still create a high resident memory footprint under specific conditions.

Exploitation & Attack Methodology

Exploiting CVE-2026-59204 requires no specific privileges and can be executed remotely if the target application processes user-supplied images. The attacker must supply a JPEG2000 file crafted with a dense grid of tiles. Because standard defensive controls in web applications typically inspect total image dimensions rather than tile density, the payload file easily bypasses standard image-resolution filters.

The attacker constructs a JPEG2000 image codestream containing a high count of small tiles (for example, a 2000x2000 pixel image divided into 10x10 pixel tiles, yielding 40,000 distinct tiles). The payload is transmitted via an image upload or manipulation endpoint. When the backend service loads the image data, Pillow's format sniffer recognizes the JPEG2000 magic bytes and routes the data stream to the decoding logic.

As the decoder processes the 40,000 tiles sequentially, the variable total_component_width increases during every iteration. By the time the loop reaches intermediate iterations, the calculated value of tile_bytes requests several gigabytes of memory. Because the system cannot satisfy this sudden request for contiguous memory, the runtime environment throws an out-of-memory error, causing the operating system to immediately terminate the worker process.

Impact Assessment & Threat Metrics

The impact of CVE-2026-59204 is restricted to application-level Denial of Service (DoS). Because the vulnerability results in process termination due to unhandled out-of-memory conditions, there is no direct risk of remote code execution or unauthorized information disclosure. However, in modern microservice architectures, a persistent crash of image processing nodes can degrade overall service availability.

The Common Vulnerability Scoring System (CVSS) v3.1 assigns a Base Score of 7.5 (High) to this flaw, reflecting network-based exploitability with low complexity and zero privilege requirements. Under CVSS v4.0, the severity is rated at 8.7 (High), emphasizing the total loss of availability for the parsing service.

The Exploit Prediction Scoring System (EPSS) maintains a low immediate probability of active exploitation in wild campaigns. The vulnerability is not currently listed in the CISA Known Exploited Vulnerabilities (KEV) catalog, and there are no public weaponized exploits available.

Detection & Technical Mitigations

Organizations running vulnerable Pillow instances should upgrade to version 12.3.0 or later to patch the underlying C source files. When immediate library upgrades are not feasible, security administrators can implement input filtering at the application boundary to reject JPEG2000 images before they reach the decoding subsystem.

The most effective application-level workaround is to restrict the permitted image formats during the invocation of Image.open(). By explicitly specifying an allowed format list, the Pillow engine will reject JPEG2000 codestreams without attempting to parse them.

from PIL import Image
 
# Enforce an explicit format whitelist excluding JPEG2000
SAFE_FORMATS = ["PNG", "JPEG", "GIF", "WEBP"]
 
try:
    with Image.open("user_file.bin", formats=SAFE_FORMATS) as img:
        img.load()
except Exception as err:
    # Handle rejected format safely
    pass

To mitigate the system-level impact of potential memory exhaustion, deploy image-processing workers inside isolated execution environments with strict resource constraints. For example, Docker containers can be configured with memory ceilings to prevent a single parsing process from consuming host resources or affecting neighboring services. This ensures that process termination affects only the processing container and does not cause host-level cascading failures.

Fix Analysis (1)

Technical Appendix

CVSS Score
7.5/ 10
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
EPSS Probability
0.40%
Top 68% most exploited

Affected Systems

python-pillow/Pillow

Affected Versions Detail

Product
Affected Versions
Fixed Version
Pillow
python-pillow
>= 8.2.0, < 12.3.012.3.0
AttributeDetail
CWE IDCWE-789 / CWE-770
Attack VectorNetwork (Unauthenticated)
CVSS Score7.5 (v3.1) / 8.7 (v4.0)
EPSS Score0.00398 (32.21% Percentile)
ImpactDenial of Service (OOM Crash)
Exploit StatusNone / No Public Exploits
KEV StatusNot Listed

MITRE ATT&CK Mapping

T1499.004Endpoint Denial of Service: Application Exhaustion
Impact
CWE-789
Memory Allocation with Excessive Size Value

The product allocates memory based on an untrusted size value, but it does not validate or limit the size of the request, leading to potential resource exhaustion.

Vulnerability Timeline

Fix commit merged in pull request #9704
2026-06-22
Security Advisory published and CVE-2026-59204 assigned
2026-07-14

References & Sources

  • [1]GitHub Security Advisory GHSA-vjc4-5qp5-m44j
  • [2]NVD CVE-2026-59204 Detail
  • [3]Official Security Fix Commit
  • [4]Vulnerability Fix Pull Request (#9704)
  • [5]Pillow 12.3.0 Release Notes
  • [6]CVE.org Record

Attack Flow Diagram

Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.
Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.

More Reports

•40 minutes ago•CVE-2026-50659
6.5

CVE-2026-50659: SMTP Command and Header Injection in .NET System.Net.Mail

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.

Alon Barad
Alon Barad
0 views•8 min read
•about 2 hours ago•CVE-2026-50651
7.5

CVE-2026-50651: Denial of Service via Uncontrolled Resource Allocation in .NET System.Net.Http

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.

Amit Schendel
Amit Schendel
4 views•6 min read
•about 3 hours ago•CVE-2026-59197
8.2

CVE-2026-59197: Heap Out-of-Bounds Write and Division-by-Zero in Pillow libImaging

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.

Alon Barad
Alon Barad
3 views•3 min read
•about 4 hours ago•CVE-2026-59198
6.5

CVE-2026-59198: Heap Out-of-Bounds Read in Pillow TGA RLE Encoder

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.

Alon Barad
Alon Barad
3 views•8 min read
•about 5 hours ago•CVE-2026-59199
7.5

CVE-2026-59199: Signed 32-Bit Integer Overflow and Heap Backward Underwrite in Pillow

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.

Alon Barad
Alon Barad
7 views•6 min read
•about 6 hours ago•CVE-2026-59200
7.5

CVE-2026-59200: Remote Denial of Service via PDF Decompression Bomb in Pillow

CVE-2026-59200 is a high-severity uncontrolled resource consumption vulnerability in the Pillow Python Imaging Library. The flaw resides in the PDF stream decoder, allowing remote, unauthenticated attackers to trigger host out-of-memory crashes by submitting malicious PDF decompression bombs.

Alon Barad
Alon Barad
7 views•5 min read