fix: detect Office Open XML formats from ZIP contents when filename has no extension#3073
Merged
dolfim-ibm merged 2 commits intodocling-project:mainfrom Mar 6, 2026
Conversation
…as no extension Pre-signed URLs (S3/GCS/Azure) often lack a Content-Disposition header, causing the resolved filename to have no .docx/.xlsx/.pptx extension. Since these formats are ZIP-based, filetype reports "application/zip", and the extension-only disambiguation fails, leaving format as None. Add _detect_office_mime_from_zip() that inspects the ZIP archive's internal structure (word/document.xml, xl/workbook.xml, ppt/presentation.xml) as a fallback when extension-based detection cannot disambiguate. Signed-off-by: Debaditya Shome <[email protected]> Made-with: Cursor
Contributor
|
✅ DCO Check Passed Thanks @DebadityaQU, all your commits are properly signed off. 🎉 |
Merge ProtectionsYour pull request matches the following merge protections and will not be merged until they are valid. 🟢 Enforce conventional commitWonderful, this rule succeeded.Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
…tension Cover the introspection fallback for DOCX and PPTX streams and paths with no file extension, and verify plain (non-Office) ZIP archives still return None. Also fix an IndexError on Path inputs with no suffix where obj.suffixes[-1] would crash on an empty list — use obj.suffix instead. Signed-off-by: Debaditya Shome <[email protected]> Made-with: Cursor
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
PeterStaar-IBM
approved these changes
Mar 6, 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
Content-Dispositionheader with the original filename._guess_format()identifies these files asapplication/zip(correct, since Office Open XML formats are ZIP-based), then attempts to disambiguate using only the filename extension. For pre-signed URLs, the resolved filename often has no extension (e.g.abc123-def456), so disambiguation fails,_guess_format()returnsNone, and the document is rejected as "File format not allowed"._detect_office_mime_from_zip()that inspects the ZIP archive's internal structure as a fallback when extension-based detection cannot disambiguate. It checks for canonical marker files:word/document.xml→ DOCXxl/workbook.xml→ XLSXppt/presentation.xml→ PPTXThis fallback is applied in both the
PathandDocumentStreambranches of_guess_format().Test plan
.docxextension still resolve correctly (no regression).ziparchives) still returnNoneas beforeBadZipFileis caught)