fix: detect OOXML docs with reordered ZIP entries - #128
Open
RickyQzh wants to merge 1 commit into
Open
Conversation
Keep the legacy positional heuristic, then parse ZIP local headers to match Content_Types, package relationships, and canonical main parts when entry order differs from what the old detector expects. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Pull request overview
This PR improves OOXML (docx/xlsx/pptx) detection for ZIP archives whose local file headers appear in an order that the legacy positional heuristic can’t reliably classify, by adding a structured scan that parses ZIP local headers and looks for required package markers plus canonical main parts.
Changes:
- Keep the legacy OOXML detector as a fast path, then add a structured ZIP local-header walk to classify OOXML even when entry order differs.
- Add canonical main-part matching (
word/document.xml,xl/workbook.xml,ppt/presentation.xml) and ambiguity handling (conflicting main parts). - Add targeted tests covering reordered entries, misleading
PK\x03\x04bytes inside payload/extra fields, conservative fallbacks (ZIP64/data-descriptor), and scan limits.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/doc.rs | Adds synthetic ZIP-local-header builders and regression tests for order-independent OOXML detection and conservative fallbacks. |
| src/matchers/doc.rs | Adds a structured OOXML scan that parses ZIP local headers to find required OPC markers and canonical main parts, while preserving legacy behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+231
to
+233
| // A ZIP local header is at least 30 bytes, so infer's 8 KiB path read can | ||
| // contain at most 273 complete headers. Keep the success case exactly at | ||
| // the limit and document the conservative direct-buffer boundary after it. |
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.
Keep the legacy positional heuristic, then parse ZIP local headers to match Content_Types, package relationships, and canonical main parts when entry order differs from what the old detector expects.