ahupp / python-magic

A python wrapper for libmagic
Other
2.6k stars 280 forks source link

[Bug Report] MP4 Major Brand type iso5 is not being correctly detected #259

Closed bypie5 closed 2 years ago

bypie5 commented 2 years ago

magic incorrectly labels MP4 videos with ftypiso5 in their header. This seems to be an issue with libmagic itself. For more information about this bug, see this bug report for libmagic: https://mailman.astron.com/pipermail/file/2020-November/000441.html

Relevant part quoted below:

Hi, We use libmagic to detect file formats and we got a report[1] that some MP4 files aren't detected properly. The file in question has a "\0\0\0$ftypiso5" signature of which "ftyp" is correctly detected as "ISO Media" (which annoyingly gives a application/octet-steam MIME type instead of some video/* fallback). The "iso5" part isn't detected by libmagic and looking into /magic/Magdir/animation and https://github.com/FFmpeg/FFmpeg/blob/290de647595051034d8f021f24bb4610b2f39943/libavformat/movenc.c#L4925-L4961 you seem to be lacking a lot of MP4(-ish?) signatures. Best regards, Haelwenn (lanodan) Monnier 1: https://git.pleroma.social/pleroma/pleroma/-/issues/2287

mmulqueen commented 2 years ago

Ubuntu 22.04 (Jammy) has libmagic1 at version 5.41, which has the linked bug fixes and solves the problem for me. Focal's libmagic1 is an older version.

To save time for anyone else looking into this: This is the relevant file in libmagic: https://github.com/file/file/blob/edd157a719a0cdb3739b7ca946fe40610118f3dd/magic/Magdir/animation

If upgrading isn't an option for you, I saw that python-magic allows you directly specify a magic file magic.Magic(magic_file="path_to_magic_file"), so it may be possible to take a newer magic file and use it with your existing installation. I don't know if doing this is a good idea or not, I opted to upgrade our base image instead.