Skip to content

fix: detect OOXML docs with reordered ZIP entries - #128

Open
RickyQzh wants to merge 1 commit into
bojand:masterfrom
RickyQzh:fix/ooxml-order-independent-detection
Open

fix: detect OOXML docs with reordered ZIP entries#128
RickyQzh wants to merge 1 commit into
bojand:masterfrom
RickyQzh:fix/ooxml-order-independent-detection

Conversation

@RickyQzh

Copy link
Copy Markdown

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.

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>
Copilot AI review requested due to automatic review settings July 23, 2026 08:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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\x04 bytes 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 thread tests/doc.rs
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.
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.

2 participants