← Lab /AI/ML

MimeLens classifies file type from any byte offset, beating Magika on mid-file fragments

MimeLens achieves higher top-1 accuracy than Magika on random mid-file byte chunks

AI/ML arXiv 2 Jun 2026 Method Prototype evidence

Published as “MimeLens: Position-Agnostic Content-Type Detection for Binary Fragments”

Why it matters

MimeLens enables reliable MIME detection for streaming, carving, and forensic workflows that only have fragmentary byte data, expanding the applicability of content-type classification beyond whole-file tools.

Summary

MimeLens can identify a file's MIME type from any byte fragment, beating Magika by +10.7 pp top-1 on whole-file heads and reaching 0.855 top-1 accuracy from a single 1.4 KB packet, while roughly doubling libmagic and Magika on random mid-file disk blocks (≈0.27 top-1). The evidence is strong on the presented benchmarks, but the model is 10-100× slower per sample on CPU and its absolute accuracy on opaque mid-file data is low.

What they found 4

  1. MimeLens-medium/bpe-16k exceeds Magika v1.1 by +10.7 pp aligned top-1 on libmagic-labeled data.

    “aligned top-1 (a curated 21-class taxonomy-equivalence map applied symmetrically) 0.829 vs 0.722 (+10.7 pp)”

  2. MimeLens-byte achieves 0.855 top-1 accuracy from a single 1.4 KB UDP packet.

    “MimeLens-byte 0.855 top-1 (Wilson 95% CI [0.82, 0.88]) from a single 1.4 KB first packet.”

  3. On random mid-file 4 KB blocks, MimeLens-bpe-64k reaches 0.266 top-1, more than double libmagic (0.093) and Magika (0.112).

    “MimeLens-bpe-64k 0.266 mid-file top-1 (file-level cluster bootstrap CI [0.22, 0.32], B = 1,000) vs 0.093 libmagic and 0.112 Magika.”

  4. MimeLens inference latency on CPU is roughly one to two orders of magnitude higher than Magika.

    “MimeLens runs roughly one to two orders of magnitude slower per sample on CPU than Magika, though it matches on consumer GPUs or in batch.”

Caveats 6

  • Absolute top-1 accuracy on opaque mid-file blocks is only ~0.22-0.27, far below clean-input performance.
  • The model is significantly slower on CPU, making it unsuitable for sub-millisecond whole-file triage.
  • All ground truth is libmagic-derived, so the comparisons establish that MimeLens is a better libmagic-style classifier than Magika on this corpus, not that it is closer to objective file-type truth.
  • The network study is early-prefix cleartext UDP over loopback, not arbitrary-offset packets, TCP segmentation, loss/reordering, or encrypted transport.
  • The disk study uses a forensic-stress distribution that over-represents compressed and encrypted formats, so results may not generalize to typical disk mixes.
  • Every reported figure is a frozen-probe number; end-to-end fine-tuning could shift the numbers.

What’s new here 3

  • Trains on uniformly random offsets within files, removing any head-of-file bias.
  • Applies a BERT-style transformer to arbitrary-position byte chunks for 125-class MIME taxonomy.
  • Demonstrates effective classification on single-packet payloads and random disk blocks where whole-file classifiers fail.