Repository navigation
fix: decode image pages on demand and limit decoded image pixels - #4976
Merged
Merged
Conversation
The image backend decoded every frame of a multi-frame image when it was opened, before the page count was checked against max_num_pages, and kept all frames in memory. It now reads only the frame count when opened and decodes each frame in load_page, so page limits apply before any pixel data is decoded and memory holds only the pages in flight. A new max_image_pixels option (default 89,478,485, the default of Pillow's Image.MAX_IMAGE_PIXELS) limits the width x height of one decoded image: - the image backend checks each frame before it is decoded; an oversized first frame rejects the document, an oversized later frame fails that page; - the shared image resource loader (HTML, Markdown, AsciiDoc, JATS, ODF) and the MHTML resources check the image header before decoding, and skip an oversized image, or one Pillow refuses to open, with a warning instead of failing the document. The loader also checks the decoded size of a base64 data URI before it decodes it. Signed-off-by: Michele Dolfi <dol@zurich.ibm.com>
Contributor
|
✅ DCO Check Passed Thanks @dolfim-ibm, all your commits are properly signed off. 🎉 |
Contributor
Merge Protections🟢 Merge protection satisfied — ready to merge. Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
Contributor
AI triage (advisory)Checked commit Warning The AI analysis did not finish. Only the deterministic checks are shown. Topic labels added: CI safety: not assessed. Possibly related pull requests
The |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
PeterStaar-IBM
approved these changes
Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
load_page.max_num_pagesis checked before any pixel data is decoded, and only the pages in flight are kept in memory.max_image_pixelsoption (default 89,478,485, Pillow'sImage.MAX_IMAGE_PIXELSdefault) limits width x height of one decoded image:Behavior changes
Tests
max_num_pagesis rejected without decoding frames.Docs:
docs/usage/advanced_options.mdand the usage skill reference.