Repository navigation
fix: limit the decompressed size of DOCX, XLSX and EPUB archive members - #4977
Conversation
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>
|
✅ DCO Check Passed Thanks @dolfim-ibm, all your commits are properly signed off. 🎉 |
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/
|
AI triage (advisory)Checked commit The PR adds CI safety: no concern found. A maintainer must still approve CI. 2 related pull request(s) in the same code
The |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
…-budget Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> # Conflicts: # docs/usage/advanced_options.md
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
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 withArchiveLimitError(aDocumentLoadError).load_msword_filebefore the relationship scan and python-docx; the Strict and fragment-only rewrites use the same limits.load_workbook; bounded reads for comment, drawing and image members (_MAX_DRAWING_BYTES/_MAX_IMAGE_BYTESare now applied).EpubBackendOptionslimits.max_file_bytes(128 MiB),max_total_bytes(512 MiB),max_member_count(10,000) onMsWordBackendOptionsandMsExcelBackendOptions, documented in the advanced options page and the usage skill.Behavior changes
ArchiveLimitErrorinstead ofSecurityError.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.