View Issue Details

IDProjectCategoryView StatusLast Update
0000373fileGeneralpublic2022-08-03 01:04
Reportervismarli Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Product Version5.34 
Summary0000373: only match first out of multiple magic files
DescriptionIf we specify multiple magic files with "-m" and the file has matching from all of them, only the first magic with match will be evaluated, the rest will not be evaluated.

for example, with "-m magicA:magicB:magicC" I observed the following:
* if file has matching in magicA, magicB and magicC: only magicA will be evaluated
* if file has matching in magicB and magicC : magicA and magicB will be evaluated, magicC won't be evaluated
* if file has matching in magicC only : magicA, magicB and magicC will be evaluated

not sure if this is expected behavior, from manual page it didn't mention any shortcut in evaluating multiple magic files nor any details of how multiple magic files will be evaluated.
Steps To Reproduce$ cat magicA
0 search {\\rt1 RTF1.0
16 search ViVa2 Viva File 2.0

$ cat magicB
6 search ABCD ABCD File
10 search TesT Test File 1.0

$ xxd test-file-AB
0000000: 7b5c 7274 3120 4142 4344 5465 7354 2078 {\rt1 ABCDTesT x
0000010: 7856 6956 6132 xViVa2

$ file -km magicA test-file-AB
test-file-AB: RTF1.0\012- Viva File 2.0, ASCII text, with no line terminators\012- data
$ file -km magicB test-file-AB
test-file-AB: ABCD File\012- Test File 1.0, ASCII text, with no line terminators\012- data

$ file -km magicA:magicB test-file-AB
test-file-AB: RTF1.0\012- Viva File 2.0, ASCII text, with no line terminators\012- data

$ file -km magicB:magicA test-file-AB
test-file-AB: ABCD File\012- Test File 1.0, ASCII text, with no line terminators\012- data

Additional Information$ file -d -km magicA:magicB test-file-AB
[try zmagic 0]
[try tar 0]
[try cdf 0]
[try elf 0]
[try softmagic 0]
bb=[0x1f37280,22], 0 [b=0x1f37280,22], [o=0, c=0]
mget(type=20, flag=0x40, offset=0, o=0, nbytes=22, il=0, nc=0)
mget/96 @0: \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000

1: > 0 search,={\rt1,"RTF1.0"]
0 == 0 = 1
bb=[0x1f37280,22], 16 [b=0x1f37280,22], [o=0x10, c=0]
mget(type=20, flag=0x40, offset=16, o=0, nbytes=22, il=0, nc=0)
mget/96 @16: \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000

2: > 16 search,=ViVa2,"Viva File 2.0"]
0 == 0 = 1
[try ascmagic 1]
test-file-AB: RTF1.0\012- Viva File 2.0, ASCII text, with no line terminators\012- data





$ file -d -km magicB:magicA test-file-AB
[try zmagic 0]
[try tar 0]
[try cdf 0]
[try elf 0]
[try softmagic 0]
bb=[0x794280,22], 6 [b=0x794280,22], [o=0x6, c=0]
mget(type=20, flag=0x40, offset=6, o=0, nbytes=22, il=0, nc=0)
mget/96 @6: \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000

1: > 6 search,=ABCD,"ABCD File"]
0 == 0 = 1
bb=[0x794280,22], 10 [b=0x794280,22], [o=0xa, c=0]
mget(type=20, flag=0x40, offset=10, o=0, nbytes=22, il=0, nc=0)
mget/96 @10: \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000

2: > 10 search,=TesT,"Test File 1.0"]
0 == 0 = 1
[try ascmagic 1]
test-file-AB: ABCD File\012- Test File 1.0, ASCII text, with no line terminators\012- data

TagsNo tags attached.

Activities

vismarli

2022-08-03 01:04

reporter   ~0003796

Intuitively if I specify multiple magic files e.g. "magicA:magicB", I expects libmagic to evaluate all rules from magicA+magicB combined/union-ed. But apparently its not that straightforward.
Please tell me if its a bug or it's expected, can anyone clarify the behavior of multiple magic files via "-m" argument?

Issue History

Date Modified Username Field Change
2022-08-02 18:58 vismarli New Issue
2022-08-03 01:04 vismarli Note Added: 0003796