View Issue Details

IDProjectCategoryView StatusLast Update
0000373fileGeneralpublic2022-10-09 18:53
Reportervismarli Assigned Tochristos  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionreopened 
Product Version5.34 
Fixed in Version5.43 
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?

vismarli

2022-08-16 14:40

reporter   ~0003797

Adding more clarifying information:
* arguments to trigger this issue are: keep-going (-k) with multiple magic files specified in (-m) argument
* the issue is always reproducible
* this issue also occurs in latest version 5.42

christos

2022-08-17 08:45

manager   ~0003798

Fixed, thanks!

vismarli

2022-08-17 16:03

reporter   ~0003801

thanks christos for the update, I can see all rules from multiple files are now hits correctly, but the output separator is not correct.

I got something like this from testing with multiple magic "magicB:magicA" :
MagicB-Rule1\012- MagicB-Rule2MagicA-Rule1\012- MagicA-Rule2, ASCII text, with no line terminators

the "MagicB-Rule2" supposed to be separated from "MagicA-Rule1".

I believe the "firstline" flag in match() should not be initialized to 1, it should be based on "need_separator" and "printed_something" flags.

christos

2022-08-18 07:58

manager   ~0003804

Yup, fixed.

vismarli

2022-08-18 17:27

reporter   ~0003807

looks great now, thank you christos. you can close this ticket.

christos

2022-10-09 18:53

manager   ~0003831

Verified fixed.

Issue History

Date Modified Username Field Change
2022-08-02 18:58 vismarli New Issue
2022-08-03 01:04 vismarli Note Added: 0003796
2022-08-16 14:40 vismarli Note Added: 0003797
2022-08-17 08:45 christos Assigned To => christos
2022-08-17 08:45 christos Status new => assigned
2022-08-17 08:45 christos Status assigned => resolved
2022-08-17 08:45 christos Resolution open => fixed
2022-08-17 08:45 christos Fixed in Version => 5.43
2022-08-17 08:45 christos Note Added: 0003798
2022-08-17 16:03 vismarli Status resolved => feedback
2022-08-17 16:03 vismarli Resolution fixed => reopened
2022-08-17 16:03 vismarli Note Added: 0003801
2022-08-18 07:58 christos Note Added: 0003804
2022-08-18 17:27 vismarli Note Added: 0003807
2022-08-18 17:27 vismarli Status feedback => assigned
2022-10-09 18:53 christos Status assigned => resolved
2022-10-09 18:53 christos Note Added: 0003831