11.1-RELEASE: magic hosed, file recognition fails

Peter pmc at citylink.dinoex.sub.org
Tue Aug 8 02:13:42 UTC 2017


Just found that my scripts that would detect image types by means of the 
"file" command do not work anymore in RELEASE-11. :(

Whats happening in R11.1 is this:

$ scanimage > /tmp/SCAN
$ file /tmp/SCAN
/tmp/SCAN: data

While on R10 in looked this way, which appears slightly more useful:

$ scanimage > /tmp/SCAN
$ file /tmp/SCAN
/tmp/SCAN: Netpbm image data, size = 2480 x 3507, rawbits, greymap


Further investigation shows, the problem may have appeared with this update:

 >r309847 | delphij | 2016-12-11 08:33:02 +0100 (Sun, 11 Dec 2016) | 2 lines
 >
 >MFC r308420: MFV r308392: file 5.29.


And that is a contrib, it seems the original comes from fishy penguins. 
So no proper repo, and doubtful if anybody might be in charge,
but instead some colorful pictures like this one:
https://fossies.org/diffs/file/5.28_vs_5.29/magic/Magdir/images-diff.html
---------------------------------------------------------------

Looking closer - this is my file header:

pmc at disp:604:1/tmp$ hd SCAN  |more
00000000  50 35 0a 23 20 53 41 4e  45 20 64 61 74 61 20 66  |P5.# SANE 
data f|
00000010  6f 6c 6c 6f 77 73 0a 32  34 38 30 20 33 35 30 37  |ollows.2480 
3507|
00000020  0a 32 35 35 0a 5f 58 56  4b 53 49 4b 52 54 50 51 
|.255._XVKSIKRTPQ|
00000030  4e 4c 52 5b 56 55 4c 47  4e 4f 4e 4d 53 54 53 4d 
|NLR[VULGNONMSTSM|
00000040  53 49 50 52 4c 51 4f 53  56 55 53 4d 55 4e 4e 4c 
|SIPRLQOSVUSMUNNL|
00000050  55 49 4d 50 52 4c 4e 50  4d 56 4e 51 52 4e 4e 50 
|UIMPRLNPMVNQRNNP|


And this is the ruleset in the magic file:

# PBMPLUS images
# The next byte following the magic is always whitespace.
# strength is changed to try these patterns before "x86 boot sector"
0       name            netpbm
 >3      regex/s         =[0-9]{1,50}\ [0-9]{1,50}       Netpbm image data
 >>&0    regex           =[0-9]{1,50}                    \b, size = %s x
 >>>&0   regex           =[0-9]{1,50}                    \b %s

0       string          P5
 >0      regex/4         P5\\s
 >>0     use             netpbm
 >>>0    string          x       \b, rawbits, pixmap
!:strength + 45
!:mime  image/x-portable-pixmap


The failing line is the one with "regex/4" command, and I dont see why 
there is a *double* \ - but a single one doesnt work either. Using \n
instead, would work.  And what also works is this one:
 >0      regex/4         P5[[:space:]]


To figure the root cause would mean to look into that libmagic, and 
maybe there is a misunderstanding between the design of that lib and the 
linux guys maintaining the magic file?



More information about the freebsd-stable mailing list