Skip to content

Tracking: the 14 stems skipped in test_file_corpus, and the ten causes behind them #3480

Description

@ESultanik

Summary

tests/test_magic.py::test_file_corpus excludes 14 stems from the upstream libmagic corpus behind a single blanket comment:

if testfile.stem not in (
        "JW07022A.mp3", "gedcom", "cmd1", "cmd2", "cmd3", "cmd4", "jpeg-text", "jsonlines1",
        "multiple", "osm", "pnm1", "pnm2", "pnm3", "utf16xmlsvg"
):
    # The files we skip fail because there is a bug in our implementation that we have not yet fixed

The comment records that bugs exist but not which ones, so the list is not actionable and there is no way to tell when one of them is fixed. Running each skipped stem shows the 14 failures are a handful of distinct causes rather than 14 separate problems.

Inventory

Measured on master (commit eed1f27) with the libmagic 5.48 corpus, using the same normalization the test applies:

stem expected PolyFile reports
pnm1 Netpbm image data, size = 2 x 2, greymap, ASCII text , greymap
pnm2 Netpbm image data, size = 2 x 2, rawbits, greymap , rawbits, greymap
pnm3 Netpbm image data, size = 10 x 20, pixmap, ASCII text , pixmap
gedcom GEDCOM genealogy text version 5.5, ASCII text GEDCOM genealogy text version 5.5 plus unmerged continuation lines
osm OpenStreetMap XML data, ASCII text OpenStreetMap XML data
cmd1 a /usr/bin/cmd1 script, ASCII text executable a /usr/bin/cmd1 script executable (binary data)
cmd2 a /usr/bin/cmd2 script, ASCII text executable ascii text
cmd3 a /usr/bin/cmd3 script executable (binary data) data
cmd4 a /usr/bin/cmd4 script executable (binary data) data
jpeg-text ASCII text, with no line terminators ascii text
jsonlines1 New Line Delimited JSON text data ascii text
multiple Viva File 2.0, then - RTF1.0, - Test File 1.0, - ABCD File, ASCII text, with no line terminators ascii text
JW07022A.mp3 Audio file with ID3 version 2.2.0, contains: MPEG ADTS, layer III, ... Audio file with ID3 version 2.2.0, contains: data
utf16xmlsvg SVG Scalable Vector Graphics image, Unicode text, UTF-16, ... , EFI variable 3997439, total size: 6881395 bytes

These group into roughly four causes:

  1. The text-encoding suffix is never appended. libmagic classifies the encoding of a matched buffer and appends it, so OpenStreetMap XML data becomes OpenStreetMap XML data, ASCII text. PolyFile stops at the type description. Accounts for osm, gedcom, pnm1, pnm3, cmd1, cmd2, and utf16xmlsvg.
  2. A parent test's description is dropped when a child continues it. The three pnm results lose Netpbm image data, size = 2 x 2 and keep only the child's , greymap, leaving output that begins with a comma. This looks like the same area as cause 1 but is a separate defect: the text is missing from the middle of the description rather than the end.
  3. Custom .magic sidecars are mishandled. cmd1 through cmd4 each ship a .magic script that the test parses in place of the default matcher. cmd3 and cmd4 produce only data, meaning nothing in the sidecar matched.
  4. Multiple matches are not combined. multiple expects libmagic's \n- -joined list of every match. PolyFile reports them as separate matches, which the test's assertIn cannot express.

JW07022A.mp3 and jsonlines1 do not obviously fall into any of the four and probably want individual investigation.

A related detail

PolyFile reports the plain-text classification in lower case, ascii text, where libmagic reports ASCII text:

import polyfile.magic
polyfile.magic.local_date = polyfile.magic.utc_date
from polyfile.magic import MagicMatcher, MAGIC_DEFS

matcher = MagicMatcher.parse(*MAGIC_DEFS)
with open("file/tests/jpeg-text.testfile", "rb") as f:
    print({str(m) for m in matcher.match(f.read())})
{'ascii text'}

test_file_corpus hides this by lower-casing both sides, and carries a dedicated escape hatch for the exact string ASCII text. Since PolyFile's default output mode mimics file, the casing is user-visible even though no test sees it.

Suggested outcome

Replace the blanket comment with per-stem entries naming the cause and linking the issue that tracks it, then split causes 1 through 4 into their own issues. Cause 1 alone would unskip seven of the fourteen.

Environment

  • PolyFile at commit eed1f27
  • libmagic 5.48 corpus
  • Python 3.14

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions