Skip to content

fix: limit the decompressed size of DOCX, XLSX and EPUB archive members - #4977

Merged
dolfim-ibm merged 2 commits into
mainfrom
fix/ooxml-epub-member-budget
Oct 23, 2026
Merged

dolfim-ibm merged 2 commits into
mainfrom
fix/ooxml-epub-member-budget

Conversation

@dolfim-ibm

Copy link
Copy Markdown
Member

DOCX and XLSX files go to python-docx / openpyxl, which load the package members into memory; on the ordinary path there was no check of the decompressed member sizes. The EPUB backend read the container, package document and content documents in full.

Changes

  • New docling/backend/utils/archive_limits.py: ArchiveLimits, a declared-size check that runs before any member is read, and a bounded member read. A file over a limit fails to load with ArchiveLimitError (a DocumentLoadError).
  • DOCX: every package is checked in load_msword_file before the relationship scan and python-docx; the Strict and fragment-only rewrites use the same limits.
  • XLSX: the package is checked before load_workbook; bounded reads for comment, drawing and image members (_MAX_DRAWING_BYTES / _MAX_IMAGE_BYTES are now applied).
  • EPUB: bounded reads for container, OPF and spine documents, and a declared-size check of the spine documents on open, with the existing EpubBackendOptions limits.
  • New max_file_bytes (128 MiB), max_total_bytes (512 MiB), max_member_count (10,000) on MsWordBackendOptions and MsExcelBackendOptions, documented in the advanced options page and the usage skill.

Behavior changes

  • The previous DOCX rewrite limits (512 MiB per member, 2 GiB in total) are replaced by the new options, and an oversized package raises ArchiveLimitError instead of SecurityError.
  • An EPUB content document over the limit now fails the conversion instead of being skipped.

Tests

  • tests/test_backend_archive_limits.py: oversized members are rejected for Path and stream input before decompression (peak memory checked), converter reports the limit, total/count limits, and helper behaviour.
  • Existing DOCX, XLSX and EPUB suites and ground-truth tests pass.

DOCX and XLSX packages went to python-docx and openpyxl without a check of
the decompressed member sizes on the ordinary path, and the EPUB backend
read the container, package document and content documents in full.

Add docling.backend.utils.archive_limits with a typed ArchiveLimits, a
check of the declared member sizes that runs before any member is read,
and a bounded member read. A file that exceeds a limit fails to load with
ArchiveLimitError, a DocumentLoadError.

- DOCX: check every package in load_msword_file before the relationship
  scan and python-docx; the Strict and fragment-only rewrites use the same
  limits and bounded reads.
- XLSX: check the package before load_workbook; bounded reads for the
  person, threaded comment, drawing and image members.
- EPUB: bounded reads for container.xml, the OPF and the spine documents,
  and a check of the spine documents' declared sizes on open, with the
  existing max_file_bytes / max_total_bytes / max_member_count options.

MsWordBackendOptions and MsExcelBackendOptions get max_file_bytes
(128 MiB), max_total_bytes (512 MiB) and max_member_count (10,000).

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 docx issue related to docx backend xlsx issue related to xlsx backend labels Oct 22, 2026
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

AI triage (advisory)

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

The PR adds ArchiveLimits, check_archive_limits and read_member in archive_limits.py. They check the declared decompressed sizes of DOCX, XLSX and EPUB archives, and they cap member reads. The PR adds max_file_bytes, max_total_bytes and max_member_count to MsWordBackendOptions and MsExcelBackendOptions. An oversized file now fails with ArchiveLimitError.

CI safety: no concern found. A maintainer must still approve CI.

2 related pull request(s) in the same code
PR State Signal Assessment
#4716 open changes the same code related: Both PRs change msword_backend.py, backend_options.py and advanced_options.md. PR 4716 adds opt-in conversion of embedded Office objects. This PR adds archive size limits. The edits do not conflict in purpose.
#4958 open changes the same code related: Both PRs change msword_backend.py and test_backend_msword.py. PR 4958 hides hidden text from the default export. This PR limits archive sizes. The two fixes are independent.

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 86.95652% with 15 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
docling/backend/msexcel_backend.py 75.00% 6 Missing ⚠️
docling/backend/epub_backend.py 76.47% 3 Missing and 1 partial ⚠️
docling/backend/msword_backend.py 88.00% 2 Missing and 1 partial ⚠️
docling/backend/utils/archive_limits.py 95.34% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

PeterStaar-IBM
PeterStaar-IBM previously approved these changes Oct 23, 2026
…-budget

Signed-off-by: Michele Dolfi <dol@zurich.ibm.com>

# Conflicts:
#	docs/usage/advanced_options.md
@github-actions github-actions Bot added the ai:ci-safe AI triage found no CI-safety concern (advisory) label Oct 23, 2026
@dolfim-ibm
dolfim-ibm merged commit ce0f04c into main Oct 23, 2026
33 checks passed
@dolfim-ibm
dolfim-ibm deleted the fix/ooxml-epub-member-budget branch October 23, 2026 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:ci-safe AI triage found no CI-safety concern (advisory) bug Something isn't working docx issue related to docx backend xlsx issue related to xlsx backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants