fix(buzz-media): recover OOXML mime from zip central directory (#2964) - #3016
Open
Explaimaus-Hash wants to merge 1 commit into
Open
fix(buzz-media): recover OOXML mime from zip central directory (#2964)#3016Explaimaus-Hash wants to merge 1 commit into
Explaimaus-Hash wants to merge 1 commit into
Conversation
…#2964) Signed-off-by: Explaimaus-Hash <unnatsharma2007@gmail.com>
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.
Fixes #2964
Problem
infer's positional OOXML matcher (is_xlsx/is_docx/is_pptx) walksforward from the front of the zip, hopping local file headers within a
~6KB window to find the 3rd entry — the one whose subdirectory name
(
xl/,word/,ppt/) identifies the document type. Real spreadsheetsand documents commonly push that header past 6KB once early entries
(themes, styles,
docProps/core.xml) are populated, so the matcher givesup and
inferreports a bareapplication/zip. Small test files stayunder the window and pass; real-world files silently don't.
Fix
Added
disambiguate_ooxml_zip(): wheninferreportsapplication/zip,re-check the file's central directory instead of the local headers.
Every entry name is listed there in a fixed-size record regardless of how
large its data is, and the directory's location is computed from the
End-of-Central-Directory record at the tail of the file — no bounded
forward walk required. The generic file-upload path already buffers the
whole request body before validating, so the central directory is already
in memory here; no streaming constraint applies.
Considered raising
infer's sniff window instead, but the central-directorycheck is deterministic regardless of entry size/order, and it only kicks in
for files
inferalready resolved toapplication/zip— nothing elsechanges.
Testing
cargo test -p buzz-media— 107 passed, 0 faileddocProps/core.xml) and confirm plain zips / non-OOXML archives areleft untouched:
test_disambiguate_ooxml_zip_recovers_large_xlsxtest_validate_file_large_xlsx_detected_correctly_end_to_endtest_disambiguate_ooxml_zip_ignores_plain_ziptest_disambiguate_ooxml_zip_detects_docx_and_pptx