Skip to content

fix: decode image pages on demand and limit decoded image pixels - #4976

Merged
PeterStaar-IBM merged 1 commit into
mainfrom
fix/image-pixel-budget
Oct 23, 2026
Merged

PeterStaar-IBM merged 1 commit into
mainfrom
fix/image-pixel-budget

Conversation

@dolfim-ibm

Copy link
Copy Markdown
Member

Summary

  • The image backend now reads only the frame count when it opens an image and decodes each frame in load_page. max_num_pages is checked before any pixel data is decoded, and only the pages in flight are kept in memory.
  • New max_image_pixels option (default 89,478,485, Pillow's Image.MAX_IMAGE_PIXELS default) limits width x height of one decoded image:
    • image inputs: an oversized first frame rejects the document; an oversized later frame fails that page.
    • HTML / Markdown / MHTML (and other users of the shared image loader): an oversized image, or one Pillow refuses to open, is skipped with a warning; the rest of the document converts.
  • Base64 data URIs are size-checked before decoding.

Behavior changes

  • A decode error in one frame of a multi-page image now fails that page instead of the whole document at load time.
  • The image source stays open until the backend is unloaded.

Tests

  • Multi-frame TIFF over max_num_pages is rejected without decoding frames.
  • Pixel limit on image inputs (first frame and later frame).
  • Loader, HTML and Markdown skip oversized images and keep the other content.

Docs: docs/usage/advanced_options.md and the usage skill reference.

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>
@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @dolfim-ibm, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@github-actions github-actions Bot added bug Something isn't working html issue related to html backend markdown issue related to markdown backend labels Oct 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

AI triage (advisory)

Checked commit 6b223ba7c2. The analysis read the diff only. It did not run code from this pull request.

Warning

The AI analysis did not finish. Only the deterministic checks are shown.

Topic labels added: bug, html, markdown.

CI safety: not assessed.

Possibly related pull requests

PR State Signal Assessment
#4912 open changes the same code not assessed
#3891 open changes the same code not assessed

The ai:* labels are advisory. They do not approve CI and they do not add tests:full. A new push runs this check again.

@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.74468% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
docling/backend/image_backend.py 92.85% 0 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@PeterStaar-IBM
PeterStaar-IBM merged commit bae7aa3 into main Oct 23, 2026
33 checks passed
@PeterStaar-IBM
PeterStaar-IBM deleted the fix/image-pixel-budget branch October 23, 2026 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working html issue related to html backend markdown issue related to markdown backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants