Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Magic for xlsx #36

Merged
merged 4 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions data/custom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<magic priority="50">
<match value="PK\003\004" type="string" offset="0">
<match value="[Content_Types].xml" type="string" offset="30">
<match value="[Content_Types].xml" type="string" offset="30:65536">
<match value="word/" type="string" offset="0:4096" />
</match>

Expand All @@ -39,7 +39,7 @@

<magic priority="50">
<match value="PK\003\004" type="string" offset="0">
<match value="[Content_Types].xml" type="string" offset="30">
<match value="[Content_Types].xml" type="string" offset="30:65536">
Copy link
Contributor Author

@fursich fursich Mar 30, 2021

Choose a reason for hiding this comment

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

The composing parts of google-generated office documents seems to have reversed order. Consequently, the larger the file gets, the later magic strings appears in the file - meaning, we have to go searching for longer bytes, and some sort of trade-off would be needed at certain point.

pptx naturally has larger components (even though test fixture is nothing more than a blank slide), so it has to be at least 30:28168 to find out the string (but that'll be not enough for a pptx with a few contents, so tentatively I put 65536 bytes as maximum search range)

Looks like we have two choices here:

  1. to align with mimemagic that searches the string upto ~5000 bytes. In this case we cannot add google-generated pptx fixture, as it naturally fails.

  2. to take bigger range than mimemagic does, so that it can identify (at least) some office files.

I'm assuming the latter might make sense, but please feel free to correct me if I'm wrong.

In any case we might have to rely on other fallback strategies for larger google-generated office files. Probably the question would come down to "to what extent do we want to try hard to find out embedded magic string?" - let me know what you would think.

<match value="ppt/" type="string" offset="0:4096" />
</match>

Expand All @@ -55,7 +55,7 @@

<magic priority="50">
<match value="PK\003\004" type="string" offset="0">
<match value="[Content_Types].xml" type="string" offset="30">
<match value="[Content_Types].xml" type="string" offset="30:65536">
Copy link
Contributor Author

Choose a reason for hiding this comment

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

At least for a blank xlsx file 4096 would be sufficient. I used a common range for the three different format though, so as to make these numbers less cryptic.

<match value="xl/" type="string" offset="0:4096" />
</match>

Expand Down
6 changes: 3 additions & 3 deletions lib/marcel/tables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2160,11 +2160,11 @@ module Marcel
['audio/mpeg', [[0, "\377\362"], [0, "\377\363"], [0, "\377\364"], [0, "\377\365"], [0, "\377\366"], [0, "\377\367"], [0, "\377\372"], [0, "\377\373"], [0, "\377\374"], [0, "\377\375"], [0, "\377\377"], [0, 'ID3']]],
['application/pdf', [[0, '%PDF-'], [0, "\357\273\277%PDF-"]]],
['application/msword', [[0..8, "\320\317\021\340\241\261\032\341", [[546, 'jbjb'], [546, 'bjbj']]]]],
['application/vnd.openxmlformats-officedocument.wordprocessingml.document', [[0, "PK\003\004", [[30, '[Content_Types].xml', [[0..4096, 'word/']]], [30, '_rels/.rels', [[0..4096, 'word/']]]]]]],
['application/vnd.openxmlformats-officedocument.wordprocessingml.document', [[0, "PK\003\004", [[30..65536, '[Content_Types].xml', [[0..4096, 'word/']]], [30, '_rels/.rels', [[0..4096, 'word/']]]]]]],
['application/vnd.ms-powerpoint', [[0..8, "\320\317\021\340\241\261\032\341", [[1152..4096, "P\000o\000w\000e\000r\000P\000o\000i\000n\000t\000 D\000o\000c\000u\000m\000e\000n\000t"]]]]],
['application/vnd.openxmlformats-officedocument.presentationml.presentation', [[0, "PK\003\004", [[30, '[Content_Types].xml', [[0..4096, 'ppt/']]], [30, '_rels/.rels', [[0..4096, 'ppt/']]]]]]],
['application/vnd.openxmlformats-officedocument.presentationml.presentation', [[0, "PK\003\004", [[30..65536, '[Content_Types].xml', [[0..4096, 'ppt/']]], [30, '_rels/.rels', [[0..4096, 'ppt/']]]]]]],
['application/vnd.ms-excel', [[2080, 'Microsoft Excel 5.0 Worksheet'], [2080, 'Foglio di lavoro Microsoft Exce'], [2114, 'Biff5'], [2121, 'Biff5'], [0..8, "\320\317\021\340\241\261\032\341", [[1152..4096, "W\000o\000r\000k\000b\000o\000o\000k"]]]]],
['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', [[0, "PK\003\004", [[30, '[Content_Types].xml', [[0..4096, 'xl/']]], [30, '_rels/.rels', [[0..4096, 'xl/']]]]]]],
['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', [[0, "PK\003\004", [[30..65536, '[Content_Types].xml', [[0..4096, 'xl/']]], [30, '_rels/.rels', [[0..4096, 'xl/']]]]]]],
['application/x-dbf', [[0, "(?s)^[\\\\002\\\\003\\\\060\\\\061\\\\062\\\\103\\\\143\\\\203\\\\213\\\\313\\\\365\\\\345\\\\373].[\\\\001-\\\\014][\\\\001-\\\\037].{4}(?:.[^\\\\000]|[\\\\101-\\\\377].)(?:[^\\\\000\\\\001].|.[^\\\\000]).{31}(?<=[\\\\000][^\\\\000]{0,10})[A-Z@+]"]]],
['image/x-tga', [[1, "\001\001\000\000", [[8, ".*[\\\\124\\\\122\\\\125\\\\105\\\\126\\\\111\\\\123\\\\111\\\\117\\\\116\\\\055\\\\130\\\\106\\\\111\\\\114\\\\105\\\\056\\\\000]"]]], [1, "\000\002\000\000", [[8, ".*[\\\\124\\\\122\\\\125\\\\105\\\\126\\\\111\\\\123\\\\111\\\\117\\\\116\\\\055\\\\130\\\\106\\\\111\\\\114\\\\105\\\\056\\\\000]"]]], [1, "\000\003\000\000", [[8, ".*[\\\\124\\\\122\\\\125\\\\105\\\\126\\\\111\\\\123\\\\111\\\\117\\\\116\\\\055\\\\130\\\\106\\\\111\\\\114\\\\105\\\\056\\\\000]"]]]]],
['application/x-endnote-refer', [[0..50, '%A ', [[0..1000, "\n%D ", [[0..1000, "\n%T "]]]]]]],
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.