View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0000437 | file | General | public | 2023-03-28 08:49 | 2023-05-22 05:38 |
Reporter | laz | Assigned To | christos | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | assigned | Resolution | open | ||
Product Version | 5.44 | ||||
Summary | 0000437: Match strength not accounted in custom magic definition | ||||
Description | One can enrich the default magic database (in my case, "/usr/share/misc/magic.mgc") by adding a custom .mgc file in their home directory. Matches from this custom file however will always take precedence over the default definitions, regardless of the `strength` across all matches. | ||||
Steps To Reproduce | # custom_magic 0 search/1024 ABC ABC file !:mime application/abc !:strength - 10 # default_magic 0 search/1024 ABCD ABCD file !:mime application/abcd !:strength + 50 # file -C -m default_magic && cp default_magic.mgc /usr/local/share/misc/magic.mgc # file -C -m custom_magic && cp custom_magic.mgc ~/.magic.mgc # file --list -m /usr/local/share/misc/magic.mgc Set 0: Binary patterns: Text patterns: Strength = 88@1: ABCD file [application/abcd] Set 1: Binary patterns: Text patterns: # file --list -m ~/.magic.mgc Set 0: Binary patterns: Text patterns: Strength = 29@1: ABC file [application/abc] Set 1: Binary patterns: Text patterns: # echo "ABCD" > abcd.txt && file abcd.txt -k abcd.txt: ABC file\012- ABCD file, ASCII text The order of the returned MIME types should have been reversed - `ABCD file\012- ABC file` | ||||
Tags | magic | ||||
|
The magic strengths of patterns are implemented by sorting magic entries within a set (a file) and then matching them in sequence. This is why you see that effect once you split the magic entries across multiple files. Fixing this would be very expensive at runtime (would require merging the entries for multiple files and then re-sorting. Not impossible, but is it really worth it? |
|
Hey christos I'm not aware of the implementation of the magic entries sorting, so feel free to close this one if you think it's going to be more of a headache than actually beneficial. |
Date Modified | Username | Field | Change |
---|---|---|---|
2023-03-28 08:49 | laz | New Issue | |
2023-03-28 08:49 | laz | Tag Attached: magic | |
2023-05-21 17:26 | christos | Assigned To | => christos |
2023-05-21 17:26 | christos | Status | new => assigned |
2023-05-21 17:28 | christos | Status | assigned => feedback |
2023-05-21 17:28 | christos | Note Added: 0003939 | |
2023-05-22 05:38 | laz | Note Added: 0003941 | |
2023-05-22 05:38 | laz | Status | feedback => assigned |