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

Incorrect handling of CR2 files #69

Open
kostrub opened this issue Jun 26, 2020 · 2 comments
Open

Incorrect handling of CR2 files #69

kostrub opened this issue Jun 26, 2020 · 2 comments

Comments

@kostrub
Copy link

kostrub commented Jun 26, 2020

Hello. I have a problem when trying to process Cr2 files. filetype recognize it as both tiff and cr2 type. It's not surprise since cr2 basen on tiff .

Filetype version 1.0.7
Sample code:

from filetype.types.image import Tiff, Cr2
from filetype import match
match("Path to cr2 file", matchers=[Cr2()])
match("Path to cr2 file", matchers=[Tiff()])

Result is:

>>> match("D:\Downloads\RAW_CANON_1DM2.CR2", matchers=[Cr2()])
<filetype.types.image.Cr2 object at 0x0000029F0EF2C9E8>
>>> match("D:\Downloads\RAW_CANON_1DM2.CR2", matchers=[Tiff()])
<filetype.types.image.Tiff object at 0x0000029F0EF2CA20>

Should be:

>>> match("D:\Downloads\RAW_CANON_1DM2.CR2", matchers=[Cr2()])
<filetype.types.image.Cr2 object at 0x0000029F0EF2C9E8>
>>> match("D:\Downloads\RAW_CANON_1DM2.CR2", matchers=[Tiff()])

You can take sample cr2 here
I think to solve this problem we need to add something like and not(buf[8] == 0x43 and buf[9] == 0x52)
here to make sure that there is no Cr2 magic word in buffer.

@h2non
Copy link
Owner

h2non commented Jun 28, 2020

Happy to merge a PR with the fix.

@dosas
Copy link

dosas commented Dec 30, 2020

This problem could have never been caught with a simple test. Because of this return statement https://github.com/h2non/filetype.py/blob/master/filetype/match.py#L33 the matches (and probably also the performance) depend on the position of the Type class in the list.
Shouldn't the matcher iterate over all possible types and throw an error if more than one match is found?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants