#876316 buggy magic: mistakes many things (including .gz, .apk) as "DOS/MBR boot sector" since 2012-2013 "filesystem improvements"

Package:
file
Source:
file
Description:
Recognize the type of data in a file using "magic" numbers
Submitter:
Ximin Luo
Date:
2026-08-13 12:27:02 UTC
Severity:
important
Tags:
#876316#5
Date:
2017-09-20 22:05:11 UTC
From:
To:
Dear Maintainer,

(I would have filed this upstream but their bug tracker was down.)

In developing diffoscope we've come across many cases of file(1) misdetecting
other things as DOS/MBR boot sector. I've been dismissing these as corner cases
but now there are just too many to ignore. One example is attached.

$ file control.tar.gz
control.tar.gz: DOS/MBR boot sector; partition 1 : ID=0xd8, [..]

I git cloned https://github.com/file/file and ran my tests:

| (master)$ git clean -fdx && git reset --hard && autoreconf -i && ./configure && make && src/file -m magic/magic:magic/magic.mgc ../control.tar.gz
| [..]
| ../control.tar.gz: DOS/MBR boot sector; partition 1 : [..]

After some experimenting I found a good commit:

| $ git checkout FILE5_00
| $ git clean -fdx && git reset --hard && autoreconf -i && ./configure && make && src/file -m magic/magic:magic/magic.mgc ../control.tar.gz
| [..]
| ../control.tar.gz: gzip compressed data, from Unix, max compression

So we have a good and a bad revision, let's run a git-bisect then.

$ git bisect start
$ git bisect good FILE5_00
$ git bisect bad origin/master
$ git bisect run sh -c 'git clean -fdx && git reset --hard && autoreconf -i && ./configure && make && src/file -m magic/magic:magic/magic.mgc ../control.tar.gz | grep -i gzip; x=$?; git reset --hard; git clean -fdx; exit $x'
[..]
51ceb2bd7a728fb307f190ee68fe53cd0392fb28 is the first bad commit
commit 51ceb2bd7a728fb307f190ee68fe53cd0392fb28
Author: Christos Zoulas <christos@zoulas.com>
Date:   Fri Oct 12 16:10:39 2012 +0000

    from Joerg Jenderek
    Hi,
    2 files (TDSK-5120x32b.img and TDSK-5120x64b.img ) in directory bootsector
    are characterized wrong ( see output bootsector-5.11.txt) .
[..]
:040000 040000 b0a083f5b8453b812de42749e612aff7673b42f3 ef0015db2bdd886d15d6993c66d6562fed5572e6 M	magic
bisect run success

X

#876316#12
Date:
2017-09-20 22:11:00 UTC
From:
To:
Ximin Luo:

Whoops, here it is attached for real.

#876316#17
Date:
2017-09-20 22:28:00 UTC
From:
To:
Ximin Luo:

https://people.debian.org/~infinity0/repro/Zom-15.1.0-alpha-5-zomrelease-release-unsigned.apk

git bisect gives us a different commit:

3989f2e0a063c6a1ab58ebb34f34f12adc45efd4 is the first bad commit
commit 3989f2e0a063c6a1ab58ebb34f34f12adc45efd4
Author: Christos Zoulas <christos@zoulas.com>
Date:   Thu Mar 14 01:38:30 2013 +0000

    filesystems detail patch from joerg jenderek

:040000 040000 775d171259ca46632f42ddb923fca2fb4de26499 0c62e47e47b692e100d61b015015421e5e27829e M	magic
bisect run success

But it's from the same person and in the same topic ("improving" detection of filesystems).

X

#876316#32
Date:
2018-07-29 16:14:34 UTC
From:
To:
# Let's sort things out
unmerge 876316
retitle 849782 buggy magic: Does not detect all .apk file (mostly as .zip only)
severity 849782 normal
thanks

Ximin Luo wrote...
easy given file's capabilities, i.e. without parsing the central
directory. This is 849782/849783

Bug 876316 however is a fairly horrible regression: The initial
detection for "DOS/MBR boot sector", introduced in commit
FILE5_11-63-g51ceb2bd is *way* too weak, one in approx. 2^17 files gets
mis-detected this way. But it's still there, I'll try to get that fixed
upstream, it's doable but not that easy without introducing other
regressions.

    Christoph

#876316#39
Date:
2026-08-13 12:23:55 UTC
From:
To:
Dear Maintainer,

   * What led up to the situation?

$ wget https://bioconductor.org/packages/release/bioc/src/contrib/goseq_1.64.0.tar.gz
$ file goseq_1.64.0.tar.gz
goseq_1.64.0.tar.gz: DOS/MBR boot sector

   * What outcome did you expect instead?
It truly is a gzipped tarball.