From 8785aba47422b86306c3bb60b5a5f411d079ee10 Mon Sep 17 00:00:00 2001 From: Stephen Masters Date: Sun, 1 Nov 2026 22:49:17 +0000 Subject: [PATCH] feat!: hold every page, frame and tile to max_side on its longest side A pixel budget alone lets through a page a few pixels wide and a million tall, and an abnormally tall image is what drove libtiff's RGBA reader to write colour data to an arbitrary address (CVE-2025-9900). The new policy field max_side bounds either side of any one page, frame or tile: 30,000 by default, three times the longest side in the corpus (9,933 pixels, A3 at 600 dpi), and 15,000 under STRICT. The readers report the longest side across every frame they walk, the PDF path across every page at the render dpi, and the command takes --max-side. Breaking because a file that passed last week can be refused this week: a page, frame or tile longer than 30,000 pixels on a side now fails under the default policy. Set max_side to allow it. The proposed record for CVE-2025-9900 now names the field and the test that proves the refusal, so it can be promoted. BREAKING CHANGE: the default policy refuses a page, frame or tile longer than 30,000 pixels on either side; set max_side to allow it. Co-authored-by: Yvette Mankerian Co-Authored-By: Claude Fable 5.1 --- README.md | 1 + docs/advisories/proposed/CVE-2025-9900.json | 14 ++++-- src/sillybos/check.py | 14 ++++++ src/sillybos/cli.py | 7 +++ src/sillybos/headers.py | 32 +++++++++++-- src/sillybos/pdf.py | 15 ++++-- src/sillybos/policy.py | 19 +++++++- tests/test_check.py | 51 +++++++++++++++++++-- tests/test_cli.py | 3 ++ tests/test_headers.py | 16 +++---- 10 files changed, 146 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 2f30da9..bfceeb3 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,7 @@ check(path, Policy(formats={"tiff", "pdf"}, max_pages=50)) | `formats` | jpeg, png, tiff, pdf | the same | What may pass at all. Nothing else is ever allowed, whatever the policy says | | `max_bytes` | 512 MiB | 128 MiB | The file. Checked before anything reads it | | `max_pixels` | 89,478,485 | 50,000,000 | Any one page or frame, decoded. For a PDF page, at `render_dpi`. The default is Pillow's own decompression-bomb threshold, enforced here rather than left to a global | +| `max_side` | 30,000 | 15,000 | Either side of any one page, frame or tile. A pixel budget alone lets through a page a few pixels wide and a million tall, and an abnormally tall image is what drove libtiff's RGBA reader to write colour data to an arbitrary address (CVE-2025-9900). No scanner writes a side longer than a few tens of thousands of pixels; the default is three times the longest side in the corpus (9,933, A3 at 600 dpi) | | `max_pages` | 500 | 100 | Pages of a PDF, frames of a TIFF or animated PNG, pictures of a multi-picture JPEG. Also bounds the header walk itself | | `max_metadata_bytes` | 4 MiB | 1 MiB | The largest block of metadata in an image: a PNG chunk other than image data, a TIFF tag's out-of-line data, a JPEG colour profile across its segments. A scan carries kilobytes; a block the size of the file is where parsers' quadratic paths and allocation flaws live (CVE-2026-96643, CVE-2023-6277) | | `render_dpi` | 200 | 200 | What you will render PDF pages at, so a page's pixels are known before the renderer allocates them | diff --git a/docs/advisories/proposed/CVE-2025-9900.json b/docs/advisories/proposed/CVE-2025-9900.json index 5c31c2b..d4da1ac 100644 --- a/docs/advisories/proposed/CVE-2025-9900.json +++ b/docs/advisories/proposed/CVE-2025-9900.json @@ -13,12 +13,18 @@ "reached_by": "open", "trigger": "Reading a TIFF whose image height is abnormally large, through libtiff's RGBA image reading.", "bucket": "B", - "finding": "The height is in the first directory, which sillybos reads. A height large enough to carry the pixel count past max_pixels is already refused; a tall, narrow image within the pixel budget is not. A ceiling on either dimension on its own (no scanner writes a side longer than a few tens of thousands of pixels) would close that, as a policy field with a corpus case. Not built.", - "refusal": null, - "verified_by": [], + "finding": "The height is in the first directory, which sillybos reads. A height large enough to carry the pixel count past max_pixels was already refused; a tall, narrow image within the pixel budget was not, until max_side: every page, frame and tile is now held to it on its longest side (30,000 by default; no scanner writes a side longer than a few tens of thousands of pixels).", + "refusal": { + "check": "max_side", + "default": true, + "setting": "max_side" + }, + "verified_by": [ + "tests/test_check.py::TestHostileFiles::test_a_tall_narrow_tiff" + ], "protect": { "general": "Upgrade libtiff to a version that has the fix; the upstream record names it.", - "specific": "Set max_pixels from your corpus; until a per-dimension ceiling exists, a pixel ceiling refuses the heights the exploit needs in practice." + "specific": "Set max_side from your corpus (the longest side of your largest real page, times two or three); sillybos refuses a taller or wider image before libtiff sees it." }, "sources": [ "https://osv.dev/vulnerability/DEBIAN-CVE-2025-9900" diff --git a/src/sillybos/check.py b/src/sillybos/check.py index 5c95029..89e9f06 100644 --- a/src/sillybos/check.py +++ b/src/sillybos/check.py @@ -54,6 +54,8 @@ class Facts: max_pixels: The most pixels any one page or frame would decode to, or `None` if the page count was over the limit and the sizes were not read. + max_side: The longest side, in pixels, of any one page or frame; + `None` in the same case. encrypted: Whether a PDF is encrypted. Always `False` for an image. pages_exact: `False` when the frame walk stopped at the limit, so `pages` is a floor, not a count. @@ -85,6 +87,7 @@ class Facts: height: int pages: int max_pixels: int | None + max_side: int | None encrypted: bool = False pages_exact: bool = True coding: str | None = None @@ -227,6 +230,7 @@ def _facts(path: Path, fmt: str, f: headers.Reader, size: int, policy: Policy) - info.height, info.pages, info.max_pixels, + info.max_side, info.encrypted, features=info.features, ) @@ -237,6 +241,7 @@ def _facts(path: Path, fmt: str, f: headers.Reader, size: int, policy: Policy) - header.height, header.pages, header.max_pixels if header.complete else None, + header.max_side if header.complete else None, pages_exact=header.complete, coding=header.coding, compression=header.compression, @@ -258,6 +263,10 @@ def _against_limits(facts: Facts, policy: Policy, fmt: str) -> list[str]: reasons.append(f"more than {policy.max_pages:,} pages, which is the limit") if facts.max_pixels is not None and facts.max_pixels > policy.max_pixels: reasons.append(f"a page of {facts.max_pixels:,} pixels; the limit is {policy.max_pixels:,}") + if facts.max_side is not None and facts.max_side > policy.max_side: + reasons.append( + f"a page {facts.max_side:,} pixels on its longest side; the limit is {policy.max_side:,}" + ) if facts.metadata is not None and facts.metadata[1] > policy.max_metadata_bytes: what, size = facts.metadata reasons.append(f"a {what} of {size:,} bytes; the limit is {policy.max_metadata_bytes:,}") @@ -296,6 +305,11 @@ def _against_limits(facts: Facts, policy: Policy, fmt: str) -> list[str]: tile_pixels = facts.tile[0] * facts.tile[1] if tile_pixels > policy.max_pixels: reasons.append(f"a tile of {tile_pixels:,} pixels; the limit is {policy.max_pixels:,}") + tile_side = max(facts.tile) + if tile_side > policy.max_side: + reasons.append( + f"a tile {tile_side:,} pixels on its longest side; the limit is {policy.max_side:,}" + ) if facts.compression is not None and facts.compression not in policy.tiff_compressions: allowed = [name for name in TIFF_COMPRESSIONS if name in policy.tiff_compressions] reasons.append( diff --git a/src/sillybos/cli.py b/src/sillybos/cli.py index d339fee..ab7ec2c 100644 --- a/src/sillybos/cli.py +++ b/src/sillybos/cli.py @@ -31,6 +31,7 @@ def _policy(args: argparse.Namespace) -> Policy: for name, value in ( ("max_bytes", args.max_bytes), ("max_pixels", args.max_pixels), + ("max_side", args.max_side), ("max_pages", args.max_pages), ("max_metadata_bytes", args.max_metadata_bytes), ("max_png_bit_depth", args.max_png_bit_depth), @@ -82,6 +83,12 @@ def build_parser() -> argparse.ArgumentParser: parser.add_argument( "--max-pixels", type=int, metavar="N", help="most pixels in any one page or frame" ) + parser.add_argument( + "--max-side", + type=int, + metavar="N", + help="most pixels along either side of any one page, frame or tile", + ) parser.add_argument("--max-pages", type=int, metavar="N", help="most pages or frames") parser.add_argument( "--max-metadata-bytes", diff --git a/src/sillybos/headers.py b/src/sillybos/headers.py index 209b833..fd7cdc0 100644 --- a/src/sillybos/headers.py +++ b/src/sillybos/headers.py @@ -52,8 +52,11 @@ class Header: pages: Frames in the file (1 for an ordinary image). For a TIFF with more frames than `limit`, `limit + 1`: the walk stopped. max_pixels: The most pixels in any one frame the reader looked at. - complete: `False` if the walk stopped at the limit, so `pages` - and `max_pixels` describe only the frames it reached. + max_side: The longest side, in pixels, of any frame the reader + looked at. + complete: `False` if the walk stopped at the limit, so `pages`, + `max_pixels` and `max_side` describe only the frames it + reached. coding: For a JPEG, how its frame is coded, by a name from [sillybos.JPEG_FRAMES][] (`"baseline"`, `"progressive"`, `"lossless"`, ...). `None` for the other formats. @@ -82,6 +85,7 @@ class Header: height: int pages: int max_pixels: int + max_side: int complete: bool = True coding: str | None = None compression: str | None = None @@ -162,10 +166,18 @@ def jpeg(f: Reader, size: int, limit: int) -> Header: metadata = ("JPEG colour profile", profile) if profile else None pages = 1 max_pixels = first.width * first.height + max_side = max(first.width, first.height) for number, offset in enumerate(pictures, start=2): if pages > limit: return Header( - first.width, first.height, pages, max_pixels, False, first.coding, metadata=metadata + first.width, + first.height, + pages, + max_pixels, + max_side, + False, + first.coding, + metadata=metadata, ) if not 2 <= offset < size: raise HeaderError(f"picture {number} lies outside the file") @@ -181,8 +193,15 @@ def jpeg(f: Reader, size: int, limit: int) -> Header: ) pages += 1 max_pixels = max(max_pixels, picture.width * picture.height) + max_side = max(max_side, picture.width, picture.height) return Header( - first.width, first.height, pages, max_pixels, coding=first.coding, metadata=metadata + first.width, + first.height, + pages, + max_pixels, + max_side, + coding=first.coding, + metadata=metadata, ) @@ -373,6 +392,7 @@ def png(f: Reader, size: int, limit: int) -> Header: height, pages, width * height, + max(width, height), metadata=metadata, colour=colour, depth=depth, @@ -518,6 +538,7 @@ def tiff(f: Reader, size: int, limit: int) -> Header: tile: tuple[int, int] | None = None subsampling: str | None = None max_pixels = 0 + max_side = 0 pages = 0 while offset != 0: if pages > limit: @@ -529,6 +550,7 @@ def tiff(f: Reader, size: int, limit: int) -> Header: first[1], pages, max_pixels, + max_side, False, compression=compression, metadata=metadata, @@ -662,6 +684,7 @@ def tiff(f: Reader, size: int, limit: int) -> Header: ) pages += 1 max_pixels = max(max_pixels, width * height) + max_side = max(max_side, width, height) if first is None: first = (width, height) offset = next_offset @@ -673,6 +696,7 @@ def tiff(f: Reader, size: int, limit: int) -> Header: first[1], pages, max_pixels, + max_side, compression=compression, metadata=metadata, tile=tile, diff --git a/src/sillybos/pdf.py b/src/sillybos/pdf.py index ca91117..45e4fe4 100644 --- a/src/sillybos/pdf.py +++ b/src/sillybos/pdf.py @@ -85,6 +85,8 @@ class PdfHeader: max_pixels: The most pixels any page would render to. `None` when the page count was over the limit and the sizes were not asked for. + max_side: The longest side, in pixels at the render dpi, of any + page. `None` in the same case. features: Which of [sillybos.PDF_FEATURES][] the file carries, in that order. Attached files and launch actions are only looked for when the page count is within the limit. @@ -95,6 +97,7 @@ class PdfHeader: width: int height: int max_pixels: int | None + max_side: int | None features: tuple[str, ...] = () @@ -203,13 +206,15 @@ def pdf(path: Path, policy: Policy) -> PdfHeader: height = round(_pixels(first.group(3), policy.render_dpi)) if pages > policy.max_pages: features = _features(summary, path, policy, within_limit=False) - return PdfHeader(pages, encrypted, width, height, None, features) + return PdfHeader(pages, encrypted, width, height, None, None, features) listing = _pdfinfo(["-f", "1", "-l", str(pages)], path, policy.pdfinfo_timeout) - sizes = [ - _pixels(w, policy.render_dpi) * _pixels(h, policy.render_dpi) + sides = [ + (_pixels(w, policy.render_dpi), _pixels(h, policy.render_dpi)) for _page, w, h in _PAGE_SIZE.findall(listing) ] - if not sizes: + if not sides: raise HeaderError("pdfinfo reported no page sizes") features = _features(summary, path, policy, within_limit=True) - return PdfHeader(pages, encrypted, width, height, round(max(sizes)), features) + max_pixels = round(max(w * h for w, h in sides)) + max_side = round(max(max(w, h) for w, h in sides)) + return PdfHeader(pages, encrypted, width, height, max_pixels, max_side, features) diff --git a/src/sillybos/policy.py b/src/sillybos/policy.py index d23dc9e..f9f9ae9 100644 --- a/src/sillybos/policy.py +++ b/src/sillybos/policy.py @@ -106,6 +106,14 @@ class Policy: The default is the threshold at which Pillow warns of a decompression bomb, enforced here rather than left to a global that another library may have raised. + max_side: The most pixels along either side of any one page, frame + or tile. A pixel budget alone lets through a page a few pixels + wide and a million tall, and an abnormally tall image is what + drove libtiff's RGBA reader to write colour data to an + arbitrary address (CVE-2025-9900). No scanner writes a side + longer than a few tens of thousands of pixels: the default is + three times the longest side in the corpus (9,933 pixels, A3 at + 600 dpi). max_pages: The most pages in a PDF, or frames in a multi-frame TIFF or animated PNG. Bounds the time and the memory a run takes, and stops the header walk itself on a file with a million @@ -184,6 +192,7 @@ class Policy: formats: frozenset[str] = field(default_factory=lambda: frozenset(FORMATS)) max_bytes: int = 512 * MIB max_pixels: int = 89_478_485 + max_side: int = 30_000 max_pages: int = 500 max_metadata_bytes: int = 4 * MIB render_dpi: int = 200 @@ -252,7 +261,14 @@ def __post_init__(self) -> None: raise ValueError( f"unknown PDF feature(s) {sorted(unknown)}; the features are {', '.join(PDF_FEATURES)}" ) - for name in ("max_bytes", "max_pixels", "max_pages", "max_metadata_bytes", "render_dpi"): + for name in ( + "max_bytes", + "max_pixels", + "max_side", + "max_pages", + "max_metadata_bytes", + "render_dpi", + ): if getattr(self, name) < 1: raise ValueError(f"{name} must be at least 1") if self.pdfinfo_timeout <= 0: @@ -269,6 +285,7 @@ def allows(self, fmt: str) -> bool: STRICT = Policy( max_bytes=128 * MIB, max_pixels=50_000_000, + max_side=15_000, max_pages=100, max_metadata_bytes=1 * MIB, max_png_bit_depth=8, diff --git a/tests/test_check.py b/tests/test_check.py index f389450..b879259 100644 --- a/tests/test_check.py +++ b/tests/test_check.py @@ -86,7 +86,10 @@ def test_a_jpeg_called_png(self, tmp_path: Path) -> None: def test_a_pixel_bomb(self, tmp_path: Path) -> None: verdict = check(corpus.write(tmp_path / "bomb.png", corpus.png(100_000, 100_000))) - assert verdict.reasons == ("a page of 10,000,000,000 pixels; the limit is 89,478,485",) + assert verdict.reasons == ( + "a page of 10,000,000,000 pixels; the limit is 89,478,485", + "a page 100,000 pixels on its longest side; the limit is 30,000", + ) assert verdict.facts is not None and verdict.facts.max_pixels == 10_000_000_000 def test_a_lossless_jpeg(self, tmp_path: Path) -> None: @@ -105,7 +108,10 @@ def test_the_policy_can_allow_a_coding(self, tmp_path: Path) -> None: def test_a_multi_picture_jpeg_whose_second_picture_is_a_bomb(self, tmp_path: Path) -> None: path = corpus.write(tmp_path / "scan.jpg", corpus.mpo([(10, 10), (65_535, 65_535)])) verdict = check(path) - assert verdict.reasons == ("a page of 4,294,836,225 pixels; the limit is 89,478,485",) + assert verdict.reasons == ( + "a page of 4,294,836,225 pixels; the limit is 89,478,485", + "a page 65,535 pixels on its longest side; the limit is 30,000", + ) assert verdict.facts is not None and verdict.facts.pages == 2 def test_a_multi_picture_jpeg_that_changes_mode(self, tmp_path: Path) -> None: @@ -166,7 +172,32 @@ def test_a_tiled_tiff_passes_by_default_and_not_under_strict(self, tmp_path: Pat def test_a_tile_bigger_than_the_pixel_limit(self, tmp_path: Path) -> None: path = corpus.write(tmp_path / "scan.tif", corpus.tiff([(10, 10)], tile=(65_535, 65_535))) - assert check(path).reasons == ("a tile of 4,294,836,225 pixels; the limit is 89,478,485",) + assert check(path).reasons == ( + "a tile of 4,294,836,225 pixels; the limit is 89,478,485", + "a tile 65,535 pixels on its longest side; the limit is 30,000", + ) + + def test_a_tall_narrow_tiff(self, tmp_path: Path) -> None: + """Within the pixel budget, but 40,000 pixels tall: what CVE-2025-9900 needs.""" + path = corpus.write(tmp_path / "tall.tif", corpus.tiff([(2_000, 40_000)], long_dims=True)) + verdict = check(path) + assert verdict.reasons == ("a page 40,000 pixels on its longest side; the limit is 30,000",) + assert verdict.facts is not None and verdict.facts.max_side == 40_000 + assert verdict.facts.max_pixels == 80_000_000 + assert check(path, Policy(max_side=40_000)).ok + + def test_a_tall_frame_among_many(self, tmp_path: Path) -> None: + frames = [(10, 10), (5, 35_000), (10, 10)] + path = corpus.write(tmp_path / "scan.tif", corpus.tiff(frames, long_dims=True)) + assert check(path).reasons == ( + "a page 35,000 pixels on its longest side; the limit is 30,000", + ) + + def test_a_long_thin_tile(self, tmp_path: Path) -> None: + path = corpus.write(tmp_path / "scan.tif", corpus.tiff([(10, 10)], tile=(40_000, 10))) + assert check(path).reasons == ( + "a tile 40,000 pixels on its longest side; the limit is 30,000", + ) def test_a_tiff_that_changes_mode_between_frames(self, tmp_path: Path) -> None: path = corpus.write( @@ -303,7 +334,17 @@ def test_a_page_the_size_of_a_wall(self, tmp_path: Path) -> None: """One A4 page and one of 200 x 300 inches: the large one is found wherever it is.""" sizes = [(595.0, 842.0), (14400.0, 21600.0)] verdict = check(corpus.write(tmp_path / "wall.pdf", corpus.pdf(2, sizes=sizes))) - assert verdict.reasons == ("a page of 2,400,000,000 pixels; the limit is 89,478,485",) + assert verdict.reasons == ( + "a page of 2,400,000,000 pixels; the limit is 89,478,485", + "a page 60,000 pixels on its longest side; the limit is 30,000", + ) + + def test_a_tall_narrow_page(self, tmp_path: Path) -> None: + """5 x 200 inches: 40 million pixels at 200 dpi, within the budget, but 40,000 tall.""" + sizes = [(595.0, 842.0), (360.0, 14400.0)] + verdict = check(corpus.write(tmp_path / "tall.pdf", corpus.pdf(2, sizes=sizes))) + assert verdict.reasons == ("a page 40,000 pixels on its longest side; the limit is 30,000",) + assert verdict.facts is not None and verdict.facts.max_side == 40_000 def test_a_file_that_is_not_a_pdf_inside(self, tmp_path: Path) -> None: verdict = check(corpus.write(tmp_path / "broken.pdf", b"%PDF-1.4\ngarbage")) @@ -365,6 +406,7 @@ def test_a_long_pdf_still_reports_what_the_summary_shows(self, tmp_path: Path) - class TestPolicy: def test_presets(self) -> None: assert DEFAULT.max_pages == 500 and STRICT.max_pages == 100 + assert DEFAULT.max_side == 30_000 and STRICT.max_side == 15_000 assert STRICT.max_bytes < DEFAULT.max_bytes @pytest.mark.parametrize( @@ -381,6 +423,7 @@ def test_presets(self) -> None: ({"tiff_subsamplings": frozenset({"3x3"})}, "unknown TIFF subsampling"), ({"tiff_subsamplings": frozenset()}, "at least one TIFF subsampling"), ({"max_pages": 0}, "max_pages must be at least 1"), + ({"max_side": 0}, "max_side must be at least 1"), ({"max_metadata_bytes": 0}, "max_metadata_bytes must be at least 1"), ({"png_colour_types": frozenset({"cmyk"})}, "unknown PNG colour type"), ({"png_colour_types": frozenset()}, "at least one PNG colour type"), diff --git a/tests/test_cli.py b/tests/test_cli.py index a71bf33..f107c42 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -42,6 +42,9 @@ def test_options_adjust_the_policy(tmp_path: Path) -> None: png = corpus.write(tmp_path / "scan.png", corpus.png(10, 10)) jpeg_called_png = corpus.write(tmp_path / "lie.png", corpus.jpeg(10, 10)) assert main(["--max-pixels", "50", str(png)]) == 1 + tall = corpus.write(tmp_path / "tall.tif", corpus.tiff([(2_000, 40_000)], long_dims=True)) + assert main([str(tall)]) == 1 + assert main(["--max-side", "40000", str(tall)]) == 0 assert main(["--formats", "jpeg,tiff", str(png)]) == 1 lossless = corpus.write(tmp_path / "lossless.jpg", corpus.jpeg(10, 10, marker=0xC3)) assert main([str(lossless)]) == 1 diff --git a/tests/test_headers.py b/tests/test_headers.py index 172c038..9dc35a2 100644 --- a/tests/test_headers.py +++ b/tests/test_headers.py @@ -29,7 +29,7 @@ def read(fmt: str, data: bytes, limit: int = 500) -> headers.Header: class TestJpeg: def test_reads_the_dimensions_from_the_frame_header(self) -> None: assert read("jpeg", corpus.jpeg(4000, 6000)) == headers.Header( - 4000, 6000, 1, 24_000_000, coding="baseline" + 4000, 6000, 1, 24_000_000, 6000, coding="baseline" ) def test_skips_segments_before_the_frame(self) -> None: @@ -38,7 +38,7 @@ def test_skips_segments_before_the_frame(self) -> None: def test_a_progressive_frame_counts_too(self) -> None: data = corpus.jpeg(30, 20).replace(b"\xff\xc0", b"\xff\xc2") - assert read("jpeg", data) == headers.Header(30, 20, 1, 600, coding="progressive") + assert read("jpeg", data) == headers.Header(30, 20, 1, 600, 30, coding="progressive") @pytest.mark.parametrize( ("marker", "coding"), @@ -62,7 +62,7 @@ def test_every_coding_name_is_one_the_policy_knows(self) -> None: def test_reads_every_picture_of_a_multi_picture_file(self) -> None: data = corpus.mpo([(30, 20), (40, 50), (10, 10)]) - assert read("jpeg", data) == headers.Header(30, 20, 3, 2000, coding="baseline") + assert read("jpeg", data) == headers.Header(30, 20, 3, 2000, 50, coding="baseline") def test_an_index_naming_one_picture_is_an_ordinary_jpeg(self) -> None: assert read("jpeg", corpus.mpo([(30, 20)])).pages == 1 @@ -147,7 +147,7 @@ def test_a_deferred_height_is_refused(self) -> None: class TestPng: def test_reads_the_dimensions_from_ihdr(self) -> None: assert read("png", corpus.png(640, 480)) == headers.Header( - 640, 480, 1, 307_200, colour="rgb", depth=8 + 640, 480, 1, 307_200, 640, colour="rgb", depth=8 ) def test_counts_the_frames_of_an_animated_png(self) -> None: @@ -179,7 +179,7 @@ class TestTiff: def test_reads_every_frame_in_either_byte_order(self, endian: str) -> None: data = corpus.tiff([(200, 300), (400, 600), (50, 50)], endian=endian) assert read("tiff", data) == headers.Header( - 200, 300, 3, 240_000, compression="none", colour="greyscale", depth=1 + 200, 300, 3, 240_000, 600, compression="none", colour="greyscale", depth=1 ) def test_reads_long_dimensions(self) -> None: @@ -235,7 +235,7 @@ def test_no_tag_means_uncompressed(self) -> None: def test_names_the_scheme(self, code: int, name: str) -> None: header = read("tiff", corpus.tiff([(10, 10), (10, 10)], compression=code)) assert header == headers.Header( - 10, 10, 2, 100, compression=name, colour="greyscale", depth=1 + 10, 10, 2, 100, 10, compression=name, colour="greyscale", depth=1 ) def test_every_scheme_name_is_one_the_policy_knows(self) -> None: @@ -545,7 +545,7 @@ def test_single_images(self, fmt: str, mode: str) -> None: buffer = io.BytesIO() Image.new(mode, (123, 45)).save(buffer, format=fmt) data = buffer.getvalue() - expected = headers.Header(123, 45, 1, 123 * 45) + expected = headers.Header(123, 45, 1, 123 * 45, 123) if fmt == "JPEG": expected = dataclasses.replace(expected, coding="baseline") elif fmt == "PNG": @@ -665,7 +665,7 @@ def test_a_progressive_jpeg_and_an_exif_jpeg(self) -> None: exif[0x0110] = "a camera" image.save(buffer, format="JPEG", progressive=True, exif=exif) assert read("jpeg", buffer.getvalue()) == headers.Header( - 64, 32, 1, 2048, coding="progressive" + 64, 32, 1, 2048, 64, coding="progressive" ) def test_a_multi_picture_jpeg(self) -> None: