Skip to content

fix: gate all local image reads behind allow_image_file_uri - #900

Merged
vagenas merged 1 commit into
mainfrom
fix/gate-local-image-paths
Oct 19, 2026
Merged

vagenas merged 1 commit into
mainfrom
fix/gate-local-image-paths

Conversation

@vagenas

@vagenas vagenas commented Oct 19, 2026

Copy link
Copy Markdown
Member

Changes

  • All reads of local image files go through ImageRef.pil_image, which now requires allow_image_file_uri for both file:// URIs and plain filesystem paths, and applies the image size limit to both. Previously plain paths, and the embedded-image path used by save_as_*, did not go through this setting.
  • New per-document option: DoclingDocument.load_local_images(base_dir=None) reads the locally referenced picture and page images into memory, and load_from_json / load_from_yaml accept allow_local_images=True, which resolves relative paths against the file's directory.
  • .dclx loading keeps its images in memory after reading them from the archive, so it keeps working by default.
  • README: new "Configuration" section describing the setting and the per-document option.
  • Tests for exports, save_as_*, page images and both options.

⚠️ Behaviour change (for the release notes)

Local image paths (plain filesystem paths and file:// URIs) are no longer read by default. To read them, either set DOCLINGCORE_ALLOW_IMAGE_FILE_URI=true, or load with DoclingDocument.load_from_json(..., allow_local_images=True) / call doc.load_local_images(). This affects, for example, a JSON saved with ImageRefMode.REFERENCED and loaded again.

ImageRef only gated file:// URIs. A plain filesystem path in an
untrusted DoclingDocument was still read when exporting with embedded
or referenced images, and _with_embedded_pictures (used by save_as_*
in EMBEDDED mode) opened file:// URIs and paths directly, bypassing
both the gate and the size limit.

Route every local read through ImageRef.pil_image, which now applies
the allow_image_file_uri opt-in and the size limit to both file:// URIs
and plain paths. DocLang archive loading caches the images it has
already validated, so loading a .dclx keeps working by default.

For trusted documents, add a per-document opt-in next to the global
setting: DoclingDocument.load_local_images() reads the locally
referenced images into memory, and load_from_json / load_from_yaml
call it via allow_local_images=True, resolving relative paths against
the file's directory. Document both in the README.

Reading local image paths now requires
DOCLINGCORE_ALLOW_IMAGE_FILE_URI=true or allow_local_images=True.

Signed-off-by: Panos Vagenas <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @vagenas, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 All 2 merge protections satisfied — ready to merge.

Show 2 satisfied protections

🟢 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)(?:\(.+\))?(!)?:

🟢 Require two reviewer for test updates

When test data is updated, we require two reviewers

  • #approved-reviews-by >= 2

@codecov

codecov Bot commented Oct 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.07692% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
docling_core/types/doc/common/reference.py 96.15% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

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.

3 participants