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

Magic for xlsx #36

merged 4 commits into from
Mar 30, 2021

Conversation

fursich
Copy link
Contributor

@fursich fursich commented Mar 29, 2021

this PR is to demonstrate reproduction case that I described with #35 .

Attached xlsx is a simple blank sheet, generated by google sheet (by exporting the original spreadsheet to xlsx).

data/custom.xml Outdated
@@ -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:4096">
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this would allow marcel to look up wider range (I have to admit it's heuristic though) for [Content_Types].xml.

I'm guessing it can be intentionally done for low cost operation, but let me know what you think.

@georgeclaghorn
Copy link
Contributor

This is fine, thanks. Could you do the same for the .docx and .pptx matches above?

@@ -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.

@@ -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.

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