Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ check(path, Policy(formats={"tiff", "pdf"}, max_pages=50))
| `jpeg_frames` | baseline, extended, progressive | the same | How a JPEG's frame may be coded. Lossless, hierarchical and arithmetic frames are legal JPEG that no scanner writes and the decoder's least-exercised code; a lossless frame was the way into a heap overflow in Pillow's JPEG decoder (CVE-2026-112403) |
| `tiff_tags` | standard, metadata, private | the same | Which kinds of tag a TIFF's directories may hold. Standard is the TIFF 6.0 set; metadata the registered blocks (XMP, IPTC, Photoshop, Exif, ICC, GPS, GeoTIFF); private everything else, the vendor and DNG tags a scan never carries. A read is not harmed by a private tag, so the default allows all three; a program that saves a file back as TIFF with its tag table carries every tag into libtiff's encoder, where a crafted one copied process memory into the output (CVE-2026-112902), and should allow standard and metadata only |
| `allow_inconsistent_tiff_tags` | no | no | Pass a TIFF whose tags contradict each other: a ColorMap of the wrong size for the bit depth (CVE-2026-112896), a floating-point Predictor on integer samples (CVE-2026-112396). No scanner writes either; both reach an encoder that trusts the tag, so the default refuses them, malformed by design or by accident. Allow only for a source known to write such files |
| `allow_spare_tiff_samples` | yes | yes | Pass a greyscale or palette TIFF whose pixels carry more samples than the one the image uses, where the rest are not a single alpha sample (two samples per pixel with ExtraSamples 0, "unspecified data"). A valid TIFF that no scanner writes; a decoder drops the spare sample, so a read is not harmed and the default allows it. A program that saves such a file back as a compressed TIFF carries its SamplesPerPixel tag into libtiff's encoder, which read two samples for every one in the row it was given and copied process memory into the output (CVE-2026-128067), and should refuse them. An alpha channel, and a spare sample on an RGB or CMYK TIFF, are not refused: there the decoder's own count is what the encoder is given |
| `allow_encrypted_pdf` | no | no | A scanned book is never encrypted |
| `pdf_features` | none | none | Which of JavaScript, forms, attached files and launch actions a PDF may carry. Each makes a viewer do something other than draw the page, and a scanned book has none. Forms are read from `pdfinfo`'s report and attached files from `pdfdetach`'s; a launch action is found by its name in the file, since no poppler tool reports one; JavaScript is looked for both ways |
| `pdf_image_codecs` | jpeg, jpx, jbig2, ccitt | the same | Which codecs a PDF's images may be coded with: JPEG, JPEG 2000 (OpenJPEG), JBIG2 and CCITT fax. Each hands the stream to a decoder of its own inside poppler, and the JBIG2 decoder is where several of its flaws have been (CVE-2025-32365, CVE-2026-93312, CVE-2026-93313). Scanners and the archives that derive PDFs from scans write all four, so both presets allow them; refuse one only when you know your source never writes it. Found by the filter's name in the file, not by `pdfimages -list`, which opens a JPX stream with OpenJPEG just to describe it |
Expand Down
3 changes: 2 additions & 1 deletion docs/advisories/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ advisory, what rides across:
a setting of `max_metadata_bytes` or `max_pages` rather than by default.
- A tag in the directory the TIFF reader already walks (private and DNG
tags, a ColorMap that does not fit the sample depth, a Predictor libtiff
rejects): B, awaiting a policy on a TIFF's tags.
rejects, a count of samples per pixel the decoder does not keep): B,
with a policy on a TIFF's tags.
- The object graph of a PDF handed to Pillow's own parser on append: C.
The check belongs in front of that PDF for what it does see, but a
cycle in the page tree is not a header field.
Expand Down
43 changes: 39 additions & 4 deletions docs/advisories/record.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"generated": "2026-11-09",
"generated": "2026-11-16",
"buckets": {
"A": "Already refused by an existing check",
"B": "Preventable from a header field our readers can see",
Expand All @@ -17,11 +17,11 @@
"other": "some other way; the finding says"
},
"counts": {
"records": 124,
"records": 125,
"refused_by_default": 46,
"by_bucket": {
"A": 39,
"B": 19,
"B": 20,
"B2": 3,
"C": 19,
"D": 3,
Expand All @@ -31,14 +31,49 @@
"by_library": {
"FreeType": 4,
"OpenJPEG": 6,
"Pillow": 61,
"Pillow": 62,
"libpng": 15,
"libtiff": 18,
"poppler": 16,
"zlib": 4
}
},
"records": [
{
"key": "CVE-2026-128067",
"aliases": [],
"library": "Pillow",
"package": "pillow",
"ecosystem": "PyPI",
"title": "Tags carried into a TIFF save make Pillow's libtiff encoder read or write past its row buffer",
"summary": "Pillow: Heap buffer overflow saving TIFF with libtiff when tags override image size",
"published": "2026-11-12",
"severity": 8.4,
"affected": "< 13.0.0",
"fixed": "13.0.0",
"reached_by": "save",
"trigger": "Opening a greyscale or palette TIFF that gives each pixel a spare sample and saving it back as TIFF; or saving any image as a compressed TIFF with the EXIF or the tag table of the file it came from.",
"bucket": "B",
"finding": "The file is the input by three routes, and the check reaches one of them. First, a greyscale or palette TIFF whose pixels carry a second sample declared unspecified (SamplesPerPixel 2, ExtraSamples 0) opens in Pillow as a one-band image while its tag still says two, and a bare save, with no option from the program, hands that tag to libtiff's encoder, which reads two samples for every one in the row. SamplesPerPixel is in the directory the reader walks, and a policy that refuses spare samples refuses the file before Pillow sees it (allow_spare_tiff_samples). It is a valid TIFF that a read is not harmed by, so the default allows it and the setting is what closes this. Second, a JPEG whose EXIF holds TIFF geometry tags (ImageWidth, SamplesPerPixel) reaches the encoder only when the program passes the file's EXIF to a compressed TIFF save; the tags sit in a block the JPEG reader measures and does not parse, so nothing refuses that file. Third, a TIFF with a rotating Orientation, which Pillow turns on load while its tags keep the old size, reaches it when the program passes the tag table or the EXIF back; that file is well formed and every rotated scan is one, so no policy could refuse it without refusing them all. A size that is stale because the program resized the image is the program's own. Tetrak OCR copies each frame before saving, which drops the tag table, and passes no EXIF, so it is not reached there.",
"refusal": {
"check": "allow_spare_tiff_samples",
"default": false,
"setting": "Policy(allow_spare_tiff_samples=False)"
},
"verified_by": [
"tests/test_check.py::TestHostileFiles::test_a_palette_tiff_with_a_spare_sample_under_a_policy_without_them"
],
"protect": {
"general": "Upgrade to Pillow 13.0.0, whose encoder refuses a scanline longer than the row it was given.",
"specific": "Refuse spare samples (allow_spare_tiff_samples) wherever a file from outside is saved back as TIFF; on a Pillow before 13.0.0, do not pass a file's own EXIF or tag table to a TIFF save (exif=, tiffinfo=); upgrade to Pillow 13.0.0."
},
"sources": [
"https://osv.dev/vulnerability/GHSA-xcvg-w56q-r89m"
],
"triaged": "2026-11-16",
"checked": "2026-11-16",
"notes": "Triaged from the advisory's text on 2026-11-16, and the bucket confirmed by a person the same day. The words filter labelled the issue likely-not-reached on \"saving\"; read against the question of what rides from an opened file into a save, the file is the input. The advisory names the palette layout for the bare save; the greyscale one was found by trying a bare save of each layout on Pillow 13.0.0, where the encoder's new guard refuses (encoder error -8) the greyscale and the palette image with an unspecified sample, and no image with an alpha channel, nor RGB or CMYK with a spare sample. The overflow itself was not reproduced on an earlier Pillow. The policy was built on 2026-11-16."
},
{
"key": "CVE-2026-107080",
"aliases": [],
Expand Down
35 changes: 35 additions & 0 deletions docs/advisories/record/CVE-2026-128067.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"key": "CVE-2026-128067",
"aliases": [],
"library": "Pillow",
"package": "pillow",
"ecosystem": "PyPI",
"title": "Tags carried into a TIFF save make Pillow's libtiff encoder read or write past its row buffer",
"summary": "Pillow: Heap buffer overflow saving TIFF with libtiff when tags override image size",
"published": "2026-11-12",
"severity": 8.4,
"affected": "< 13.0.0",
"fixed": "13.0.0",
"reached_by": "save",
"trigger": "Opening a greyscale or palette TIFF that gives each pixel a spare sample and saving it back as TIFF; or saving any image as a compressed TIFF with the EXIF or the tag table of the file it came from.",
"bucket": "B",
"finding": "The file is the input by three routes, and the check reaches one of them. First, a greyscale or palette TIFF whose pixels carry a second sample declared unspecified (SamplesPerPixel 2, ExtraSamples 0) opens in Pillow as a one-band image while its tag still says two, and a bare save, with no option from the program, hands that tag to libtiff's encoder, which reads two samples for every one in the row. SamplesPerPixel is in the directory the reader walks, and a policy that refuses spare samples refuses the file before Pillow sees it (allow_spare_tiff_samples). It is a valid TIFF that a read is not harmed by, so the default allows it and the setting is what closes this. Second, a JPEG whose EXIF holds TIFF geometry tags (ImageWidth, SamplesPerPixel) reaches the encoder only when the program passes the file's EXIF to a compressed TIFF save; the tags sit in a block the JPEG reader measures and does not parse, so nothing refuses that file. Third, a TIFF with a rotating Orientation, which Pillow turns on load while its tags keep the old size, reaches it when the program passes the tag table or the EXIF back; that file is well formed and every rotated scan is one, so no policy could refuse it without refusing them all. A size that is stale because the program resized the image is the program's own. Tetrak OCR copies each frame before saving, which drops the tag table, and passes no EXIF, so it is not reached there.",
"refusal": {
"check": "allow_spare_tiff_samples",
"default": false,
"setting": "Policy(allow_spare_tiff_samples=False)"
},
"verified_by": [
"tests/test_check.py::TestHostileFiles::test_a_palette_tiff_with_a_spare_sample_under_a_policy_without_them"
],
"protect": {
"general": "Upgrade to Pillow 13.0.0, whose encoder refuses a scanline longer than the row it was given.",
"specific": "Refuse spare samples (allow_spare_tiff_samples) wherever a file from outside is saved back as TIFF; on a Pillow before 13.0.0, do not pass a file's own EXIF or tag table to a TIFF save (exif=, tiffinfo=); upgrade to Pillow 13.0.0."
},
"sources": [
"https://osv.dev/vulnerability/GHSA-xcvg-w56q-r89m"
],
"triaged": "2026-11-16",
"checked": "2026-11-16",
"notes": "Triaged from the advisory's text on 2026-11-16, and the bucket confirmed by a person the same day. The words filter labelled the issue likely-not-reached on \"saving\"; read against the question of what rides from an opened file into a save, the file is the input. The advisory names the palette layout for the bare save; the greyscale one was found by trying a bare save of each layout on Pillow 13.0.0, where the encoder's new guard refuses (encoder error -8) the greyscale and the palette image with an unspecified sample, and no image with an alpha channel, nor RGB or CMYK with a spare sample. The overflow itself was not reproduced on an earlier Pillow. The policy was built on 2026-11-16."
}
3 changes: 2 additions & 1 deletion docs/advisories/seen.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"recorded": "2026-11-09",
"recorded": "2026-11-16",
"seen": [
"CVE-2003-0107",
"CVE-2004-0797",
Expand Down Expand Up @@ -708,6 +708,7 @@
"CVE-2026-112901",
"CVE-2026-112902",
"CVE-2026-114501",
"CVE-2026-128067",
"CVE-2026-12912",
"CVE-2026-18495",
"CVE-2026-22184",
Expand Down
1 change: 1 addition & 0 deletions scripts/fuzz_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def seeds() -> list[bytes]:
corpus.tiff([(64, 64), (32, 32), (16, 16)]),
corpus.tiff([(64, 64)], endian=">"),
corpus.tiled_tiff(256, 256, 64),
corpus.spare_sample_tiff(64, 8),
]
try:
from PIL import Image
Expand Down
12 changes: 12 additions & 0 deletions src/sillybos/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ class Facts:
and for a TIFF of standard tags only.
inconsistencies: Each way a TIFF's tags contradict each other, in
a sentence. Empty when they agree, and for the other formats.
spare_samples: How many samples each pixel of a greyscale or
palette TIFF carries beyond the one the image uses, unless
that is a single alpha sample. 0 for every other TIFF and
for the other formats.
"""

bytes: int
Expand All @@ -113,6 +117,7 @@ class Facts:
codecs: tuple[str, ...] = ()
tags: tuple[tuple[str, int], ...] = ()
inconsistencies: tuple[str, ...] = ()
spare_samples: int = 0


@dataclass(frozen=True)
Expand Down Expand Up @@ -268,6 +273,7 @@ def _facts(path: Path, fmt: str, f: headers.Reader, size: int, policy: Policy) -
subsampling=header.subsampling,
tags=header.tags,
inconsistencies=header.inconsistencies,
spare_samples=header.spare_samples,
)


Expand Down Expand Up @@ -349,6 +355,12 @@ def _against_limits(facts: Facts, policy: Policy, fmt: str) -> list[str]:
reasons.append(
"a TIFF whose tags contradict each other: " + "; ".join(facts.inconsistencies)
)
if facts.spare_samples and not policy.allow_spare_tiff_samples:
reasons.append(
f"a {facts.colour} TIFF with {facts.spare_samples + 1:,} samples per pixel, where "
"the image uses one and the rest are not an alpha channel; the policy does not "
"allow spare samples"
)
return reasons


Expand Down
8 changes: 8 additions & 0 deletions src/sillybos/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def _policy(args: argparse.Namespace) -> Policy:
changes["tiff_tags"] = frozenset(args.tiff_tags.split(","))
if args.inconsistent_tiff_tags:
changes["allow_inconsistent_tiff_tags"] = True
if args.no_spare_tiff_samples:
changes["allow_spare_tiff_samples"] = False
if args.pdf_features:
changes["pdf_features"] = frozenset(args.pdf_features.split(","))
if args.pdf_image_codecs:
Expand Down Expand Up @@ -163,6 +165,12 @@ def build_parser() -> argparse.ArgumentParser:
help="do not refuse a TIFF whose tags contradict each other (a ColorMap of the wrong "
"size, a floating-point Predictor on integer samples)",
)
parser.add_argument(
"--no-spare-tiff-samples",
action="store_true",
help="refuse a greyscale or palette TIFF whose pixels carry extra samples that are "
"not an alpha channel",
)
parser.add_argument(
"--pdf-features",
metavar="LIST",
Expand Down
33 changes: 33 additions & 0 deletions src/sillybos/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ class Header:
other, in a sentence: a ColorMap with the wrong number of
entries for the bit depth, a floating-point Predictor on
integer samples. Empty when they agree.
spare_samples: For a greyscale or palette TIFF, how many samples
each pixel carries beyond the one the image uses, unless
that is a single sample declared as alpha: 2 samples per
pixel with ExtraSamples 0 ("unspecified data") is 1. The
most in any frame the reader looked at; 0 for a TIFF whose
pixels carry only what its colour model needs, for one
with an alpha channel, for RGB, CMYK and YCbCr (where a
decoder drops the sample and keeps its own count), and for
the other formats.
"""

width: int
Expand All @@ -106,6 +115,7 @@ class Header:
subsampling: str | None = None
tags: tuple[tuple[str, int], ...] = ()
inconsistencies: tuple[str, ...] = ()
spare_samples: int = 0


def _read_exactly(f: Reader, n: int, what: str) -> bytes:
Expand Down Expand Up @@ -426,10 +436,15 @@ def png(f: Reader, size: int, limit: int) -> Header:
_YCBCR_SUBSAMPLING = 530
_PREDICTOR = 317
_COLORMAP = 320
_EXTRA_SAMPLES = 338
_SAMPLE_FORMAT = 339
_YCBCR = 6
_FLOATING_POINT_PREDICTOR = 3
_FLOATING_POINT_SAMPLES = 3
_ALPHA = (1, 2) # ExtraSamples: associated and unassociated alpha; 0 is "unspecified data"
_ONE_SAMPLE_COLOURS = ("greyscale", "palette")
"""The colour models whose pixels need one sample, and which a decoder
opens as a one-band image even when the file gives each pixel more."""
_SINGLE_VALUE_TAGS = (
_PREDICTOR,
_IMAGE_WIDTH,
Expand Down Expand Up @@ -592,6 +607,7 @@ def tiff(f: Reader, size: int, limit: int) -> Header:
subsampling: str | None = None
tags: dict[int, str] = {} # every tag outside the standard set, by number
inconsistencies: list[str] = []
spare_samples = 0
max_pixels = 0
max_side = 0
pages = 0
Expand All @@ -615,6 +631,7 @@ def tiff(f: Reader, size: int, limit: int) -> Header:
subsampling=subsampling,
tags=tuple((kind, number) for number, kind in tags.items()),
inconsistencies=tuple(inconsistencies),
spare_samples=spare_samples,
)
if offset in seen:
raise HeaderError("the frame chain loops back on itself")
Expand All @@ -639,6 +656,7 @@ def tiff(f: Reader, size: int, limit: int) -> Header:
colormap_entries: int | None = None
predictor = 1 # the tag's default: none
sample_format = 1 # the tag's default: unsigned integer
alpha: bool | None = None # whether ExtraSamples declares one alpha sample
for _ in range(count):
tag, kind, n, raw = struct.unpack(
endian + "HHI4s", _read_exactly(f, 12, "frame directory")
Expand All @@ -652,6 +670,14 @@ def tiff(f: Reader, size: int, limit: int) -> Header:
# is left as the default, since nothing here depends on
# reading it, and a wrong guess would refuse a sound file.
(sample_format,) = struct.unpack(endian + "H", raw[:2])
elif tag == _EXTRA_SAMPLES:
# Only a single SHORT can make the one extra sample alpha;
# any other shape of the tag leaves the samples undeclared.
# Should the tag appear twice, a reading that is not alpha
# stands: decoders differ on which entry they keep.
declared = kind == _TIFF_SHORT and n == 1
value = struct.unpack(endian + "H", raw[:2])[0] if declared else 0
alpha = value in _ALPHA and alpha is not False
data_size = n * _TYPE_SIZES.get(kind, 1)
if data_size > 4:
# The field holds an offset to the data. A count that would
Expand Down Expand Up @@ -734,6 +760,12 @@ def tiff(f: Reader, size: int, limit: int) -> Header:
f"frame {pages + 1} uses photometric interpretation {photometric:,}, "
"which is not one this library knows"
)
if colour in _ONE_SAMPLE_COLOURS and samples > 1 and not (samples == 2 and alpha):
# A decoder opens this as a one-band image and drops the rest,
# but the tag still says how many samples a row holds, and a
# save that carries the tag across has an encoder read that
# many from a row of one (CVE-2026-128067).
spare_samples = max(spare_samples, samples - 1)
if photometric == _YCBCR:
this_subsampling = f"{factors[0]}x{factors[1]}"
if subsampling is None:
Expand Down Expand Up @@ -788,6 +820,7 @@ def tiff(f: Reader, size: int, limit: int) -> Header:
subsampling=subsampling,
tags=tuple((kind, number) for number, kind in tags.items()),
inconsistencies=tuple(inconsistencies),
spare_samples=spare_samples,
)


Expand Down
Loading
Loading