Skip to content

feat!: refuse rare JPEG frame codings and read every picture of an MPF file - #1

Merged
stephen-masters merged 1 commit into
mainfrom
feat/jpeg-frame-coding-and-mpf
Nov 1, 2026
Merged

stephen-masters merged 1 commit into
mainfrom
feat/jpeg-frame-coding-and-mpf

Conversation

@stephen-masters

Copy link
Copy Markdown
Contributor

What

Two header checks for JPEG, from a backfill of three years of advisories against the decoders this library stands in front of.

  • Frame coding. The reader names how a JPEG's frame is coded (baseline, extended, progressive, lossless, hierarchical, arithmetic) and a new policy field, jpeg_frames, says which may pass. The default is the three a scanner writes. A lossless frame was the way into a heap overflow in Pillow's JPEG decoder (CVE-2026-112403); the other rare codings are the decoder's least exercised code. The command takes --jpeg-frames.
  • Multi-picture JPEG (MPF). A JPEG carrying a Multi-Picture index, which Pillow steps through as frames, now has every picture read with the same bounded walk. Each counts as a page, each is checked against max_pixels, and each must match the first in coding and component count, because the decoder sizes its buffers from the first. That closes the second-picture pixel bomb (CVE-2026-96636) and the mode change that overwrote the first picture's buffer (CVE-2026-96639). A malformed index, a picture outside the file, or one flagged as not JPEG is a refusal.

Why breaking

A lossless, hierarchical or arithmetic-coded JPEG, and a multi-picture JPEG whose index is malformed or whose pictures differ in coding or components, passed before and are refused now. Under AGENTS.md that is a !.

Notes

  • The MP entry's size field is ignored, as Pillow's reader ignores it. Pillow 13.0.0's writer records it wrongly from the third picture on, so trusting it would refuse real Pillow output.
  • The hostile corpus gains a frame marker and component count for plain JPEGs and a builder for multi-picture files with each hostile variant; the readers are also checked against an MPO Pillow writes.
  • README: policy table, the step-by-step description, the flag list, the promises section and the corpus description are updated in the same change.

Checks

ruff check, ruff format --check, mypy, pytest --cov (151 tests, 97%) and uv lock --check all pass locally.

🤖 Generated with Claude Code

…F file

Two checks from a backfill of three years of advisories against the
decoders this library stands in front of.

A JPEG's start-of-frame marker says how it is coded. The reader now
names the coding (baseline, extended, progressive, lossless,
hierarchical, arithmetic) and the policy's new jpeg_frames field says
which may pass; the default is the three a scanner writes. A lossless
frame was the way into a heap overflow in Pillow's JPEG decoder
(CVE-2026-112403), and the other rare codings are the decoder's least
exercised code. The command takes --jpeg-frames.

A JPEG carrying a Multi-Picture Format index (an MPO, which Pillow steps
through as frames) now has every picture read with the same bounded
walk: each counts as a page, each is checked against max_pixels, and
each must match the first in coding and component count, since the
decoder sizes its buffers from the first. That closes the second-picture
pixel bomb (CVE-2026-96636) and the mode change that overwrote the first
picture's buffer (CVE-2026-96639). A malformed index, a picture outside
the file or one flagged as not JPEG is a refusal. The entry's size field
is ignored, as Pillow's reader ignores it; Pillow 13.0.0's writer gets it
wrong from the third picture on.

BREAKING CHANGE: a lossless, hierarchical or arithmetic-coded JPEG, and
a multi-picture JPEG whose index is malformed or whose pictures differ
in coding or components, passed before and are refused now.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@stephen-masters
stephen-masters merged commit 128e981 into main Nov 1, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant