Bug #67647 [Csd]: Bundled libmagic 5.17 does not detect quicktime files correctly

From: Date: Thu, 22 Jan 2015 11:02:51 +0000
Subject: Bug #67647 [Csd]: Bundled libmagic 5.17 does not detect quicktime files correctly
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190140@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67647&edit=1

 ID:                 67647
 Updated by:         ab@php.net
 Reported by:        emkael at tlen dot pl
 Summary:            Bundled libmagic 5.17 does not detect quicktime
                     files correctly
 Status:             Closed
 Type:               Bug
 Package:            Filesystem function related
 Operating System:   Debian 3.14.12 x86_64 GNU/Linux
 PHP Version:        5.6.0RC2
 Assigned To:        ab
 Block user comment: N
 Private report:     N

 New Comment:

@emkael, thanks for the test file :)


Previous Comments:
------------------------------------------------------------------------
[2015-01-22 10:57:09] ab@php.net

Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=c9d0894ec5872f035bb2d6f1ad78fbcdf2cf20ff
Log: Fixed bug #67647 Bundled libmagic 5.17 does not detect quicktime files correctly

------------------------------------------------------------------------
[2015-01-11 04:22:17] php-bugs at lists dot php dot net

No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.

------------------------------------------------------------------------
[2015-01-07 09:57:07] emkael at tlen dot pl

Here's the smallest I could go: https://gist.github.com/emkael/ac2a48ae29d8178a567c

I've truncated the original file to a single frame (note that re-encoding with ffmpeg/lavf56
makes the problem go away) and overwritten actual video data with random bytes (for copyright
reasons) - it's still a valid QuickTime file (apart from some warnings due to that random
data), it's recognized by ffprobe/ffmpeg (as I've pasted in the gist) and produces
"floppy with old FAT filesystem 320k, Media descriptor 0xff" as finfo output.

My best guess is that either the original codec omitted some header data which made the file
detection fall to the weaker rule for FAT filesystem or that the FAT filesystem rule was being
tested too early.

I've already worked around my specific issue by falling back to a custom magic file which
detects MOV files more loosely, but since the upstream Magdir entry was reverted for being "too
weak", the same problem might occur with some other, unrelated file formats.

------------------------------------------------------------------------
[2015-01-03 12:47:24] ab@php.net

Could you please post a minimal file to reproduce? Say cut only the furst few KB or even less that
can tell the difference.

Thanks.

------------------------------------------------------------------------
[2014-07-18 08:24:44] emkael at tlen dot pl

Description:
------------
Version 5.6.0RC2 bundles libmagic in version 5.17.

That version, contrary to (i.e.) 5.19, fails to detect certain quicktime files as video/quicktime,
and serves "binary" instead.

I've attached a series of command-line tests that replicate the issue and correlate it with
libmagic version, attached below.

Unfortunately, the test does not replicate the issue with a sample MOV file from Apple's KB,
but works on various other MOV files.

The offending file magic rule was commented out from the file Magdir database in February (so,
it's fixed in libmagic version >= 5.18): https://github.com/file/file/commit/f2750e17d784dd6b21f7649965d2bd0605bfd471#diff-45a78c19f30f8e352b631e9f1d9931d2R1876

PS I'm not sure which packages does this issue belong to, apologies for that.

Test script:
---------------
user@machine:~$ hexdump -C test.mov | head -n 1
00000000  00 00 00 20 66 74 79 70  71 74 20 20 20 05 03 00  |... ftypqt   ...|

user@machine:~$ file -v
file-5.19
magic file from /etc/magic:/usr/share/misc/magic

user@machine:~$ file -b --mime-type test.mov
video/quicktime

user@machine:~$ php -i | grep libmagic
libmagic => 517

user@machine:~$ php -r '$fi = new finfo(FILEINFO_MIME_TYPE);
print($fi->file("test.mov")."\n");'
binary

user@machine:~$ php -r '$fi = new finfo();
print($fi->file("test.mov")."\n");'
floppy with old FAT filesystem 320k, Media descriptor 0xff

user@other_machine:~$ file -v
file-5.17
magic file from /etc/magic:/usr/share/misc/magic

user@other_machine:~$ file -b --mime-type test.mov
binary




------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=67647&edit=1


Thread (6 messages)

« previous php.bugs (#190140) next »