View Issue Details

IDProjectCategoryView StatusLast Update
0000664fileGeneralpublic2025-06-09 23:42
Reporterjsummers Assigned Tochristos  
PrioritynormalSeverityminorReproducibilityN/A
Status assignedResolutionopen 
Product Version5.46 
Summary0000664: Document when a 'use' test matches
DescriptionThe magic man page says nothing about when a "use" test evaluates to true. But there are about 7 patterns in the database that rely on this unspecified behavior. I suggest that the behavior be documented, and/or the problematic patterns be reviewed.
Additional InformationList of issues in magic/Magdir:

asf:119: [>0 use asf-name]
efi:44: [>>>0 use efi_sig_list]
efi:51: [>>>4 use efi_sig_list]
images:2132: [>>4 use aco-color]
images:2138: [>>4 use aco-color-v2]
images:2176: [>0 use aco-color]
measure:30: [>38400 use diy-thermocam-checker]
measure:36: [>9600 use diy-thermocam-checker]
msooxml:63: [>>>>>>>>>>>>&26 default x Microsoft OOXML]
msooxml:60: [>>>>>>>>>>&26 default x]
msooxml:57: [>>>>>>>>&26 default x]
msooxml:52: [>>>>>>&26 default x]
msooxml:44: [>>>>&26 default x]
msooxml:77: [>>>>>>>&26 default x Microsoft OOXML]
msooxml:74: [>>>>>&26 default x]
msooxml:37: [>0x1E default x]
palm:68: [>0 use aportisdoc]
pgp-binary-keys:185: [>>&0 use pgp_binary_key_pk_check]
pgp-binary-keys:193: [>>>&1 use pgp_binary_key_pk_check]
pgp-binary-keys:197: [>>&4 use pgp_binary_key_pk_check]
pgp-binary-keys:211: [>>&1 use pgp_binary_key_pk_check]
pgp-binary-keys:215: [>>&2 use pgp_binary_key_pk_check]
pgp-binary-keys:219: [>>&4 use pgp_binary_key_pk_check]
zip:121: [>(16.l) use zipcd]
TagsNo tags attached.

Activities

christos

2025-06-08 14:39

manager   ~0004259

I would have preferred if FILE_USE in softmagic.c returned just rv from the recursive match. But it returns rv || *found_match; which revision 1.336 says:

In the name->use case return true if we found a match. This fixes the case
where the name entry found a match, and the use case did not and had a
annotation type (file --mime binary.pgp.key)

But this corrupts the error case (rv == -1) so it should be handled properly.

christos

2025-06-08 14:54

manager   ~0004260

This is documented in magic.man in the "name" entry part:


Named magic entries return true if there was a match in the evaluation
of the entry, or if there was a previous existing match.

jsummers

2025-06-09 23:42

reporter   ~0004264

Thanks.

My conclusion (maybe wrong) was that a "use" line evaluates to true if and only if the named magic *prints* something, anywhere in it (including the case where it calls another named magic that prints something). A line in the named magic can evaluate to true, but if it doesn't have anything in the message field, it doesn't cause the calling "use" line to evaluate to true.

If that's reliably how it works, it seems like a very useful feature. (Sometimes in an elegant way, sometimes as a hack.)

The new documentation doesn't seem quite clear to me. If a "match" here equals printing something, that's at least inconsistent with how "default" is documented, where a "match" doesn't have to print anything.

I assumed the old documentation "Named magic entries always match" referred to the "name" line itself, which of course does always effectively evaluate to true, so that its children will be evaluated.

Issue History

Date Modified Username Field Change
2025-06-02 15:51 jsummers New Issue
2025-06-08 14:39 christos Note Added: 0004259
2025-06-08 14:53 christos Assigned To => christos
2025-06-08 14:53 christos Status new => assigned
2025-06-08 14:54 christos Status assigned => feedback
2025-06-08 14:54 christos Note Added: 0004260
2025-06-09 23:42 jsummers Note Added: 0004264
2025-06-09 23:42 jsummers Status feedback => assigned