Repository navigation
Conversation
Add hollowed test fixtures covering all 1,698 newly supported standalone binary formats across 15 category directories, bringing total resolver fixture coverage from 310 to 2,008 (1:1 with in_resolvers content types).
Expand the native Rust cascade with structural verifiers for 1,698 standalone binary formats (1,697 new content types plus existing catalog-only entry tfrecord), bringing resolver-backed content types from 310 to 2,008: - Add pure-Rust declarative byte-pattern macros (hex2bin!, le/be*_bytes!, ebcdic_bytes!) in magic/mod.rs and shared zlib/ASN.1 BER length helpers in magic/verifiers/mod.rs (zero new crate dependencies). - Add 1,486 Tier-1 (magic32) and 62 Tier-2 (magic16) O(1) prefix dispatch entries across 15 category verifier modules. - Organize 223 non-zero-offset and headerless probes in offset_probes.rs into a 4-stage O(1) prefix-length and fixed-offset switch dispatch with fast byte/size pre-filters before structural verification. - Extend the 64 KiB prefix read condition in resolvers.rs for multi-chunk Unreal Engine 2 UZ2 archives so chunk 2 is verified past PREFIX_LIMIT. - Update resolvers_identify_fixtures to assert all 2,008 fixtures.
- Add 1,697 standalone binary content types to assets/content_types.yaml (480 -> 2,177 KB entries; 404 -> 2,102 exposed labels including existing catalog entry tfrecord). - Update scripts/sync_kb.py to wrap >100-column generated Rust match arms for rustfmt and type CompactContentTypeInfo's label slot as string to avoid TypeScript TS2590 union-complexity limits across 2,102 labels. - Regenerate all KB artifacts, Rust/C/Python/JS bindings, and website content-type reference tables via scripts/sync_kb.py.
corkamig
force-pushed
the
resolvers-expand-binary
branch
from
November 15, 2026 06:42
12b2b9c to
6e55015
Compare
corkamig
marked this pull request as ready for review
November 15, 2026 07:04
- joda_tz: fix the @1/@2 poolSize overlap bug, dispatch both 'C' (CachedDateTimeZone) and 'P' (PrecalculatedZone), fully parse variable-width DateTimeZoneBuilder millis/UTF records plus optional DSTZone tail to exact EOF, and correct the KB description from ZoneInfoMap to Joda-Time Compiled Time Zone (DateTimeZone). - kens_digital_kdm: cap nnotes at 8192 (MAXNOTES), validate trquant (1..=64) and non-silent track volumes, verify all visible nttime entries are monotonic, bounded, and non-zero, and validate visible nttrack/ntfreq/nt*eff byte arrays. - clarion_mem: enforce Clarion DOS .mem block geometry (size == 6 + 256*N, N >= 1), validate firstdel and every visible block's nxtblk pointer (in-range, no self-loops, no visible free-list cycles), and verify printable DOS text payload in block 1. - Update the three resolver fixtures to full hollowed real samples and add unit tests for positive and negative cases.
reyammer
reviewed
Nov 16, 2026
reyammer
left a comment
Collaborator
There was a problem hiding this comment.
Note: This is a review from yanickf@'s bot, and yanickf@ has reviewed and approved it.
Review Verdict: CONCERNS
1. Verdict, Recommendation & Risk Assessment
- Verdict: CONCERNS (request changes before merging).
- What the PR does: Adds deterministic structural verifiers for 1,698 standalone binary formats (
1,697new KB entries plustfrecord), expanding resolver coverage from310 → 2,008content types acrossmagic32.rs,magic16.rs,offset_probes.rs, and 15verifiers/category/*.rsmodules, alongside1,698fixtures (23.3 MBon disk) and regenerated Rust/C/Python/JS/website artifacts. - What works well:
- Zero new crate dependencies; compile-time
hex2bin!,le/be*_bytes!, andebcdic_bytes!helpers inrust/lib/src/resolvers/magic/mod.rsare clean and readable, and commit3d53eb00nicely tightenedjoda_tz,kens_digital_kdm, andclarion_mem. - Non-matching hot-path latency remains very low (~
4.1 µsper 4 KiB binary miss, ~5.5 µsper 4 KiB Python text miss in release builds). sync_kb.py --self-test(53/53),sync_kb.py --check,check_copyright.py,check_documentation.py,cargo test(rust/lib), andgo test ./...all pass.
- Zero new crate dependencies; compile-time
- Risk Assessment: High.
- False positives short-circuit ML inference: Any resolver hit immediately returns that
ContentTypewithout model evaluation. Empirical testing against the compiledlibmagikareproduced false positives on ANSI-colored CLI/CI logs (cargo,git diff,ls), valid 2-space pretty-printed JSON, TSV files, SPICE netlists, UTF-32LE text, 54 UTF-8 prose prefixes, and 1 in ~40k random / 1 in ~7k sparse binary inputs. - Debug panics & release wraparounds: Three
u64additions (verify_criware_cpk,verify_android_ota,verify_sff) panic in 64-bit debug builds and wrap modulo2^64into false positives in release builds; additionalusizeadditions overflow on 32-bitwasm32. - Irreversible API surface:
assets/exposed_content_types.txtis append-only monotonic—every added label name is permanent public API across Rust, Python, and JS/TS.
- False positives short-circuit ML inference: Any resolver hit immediately returns that
2. Review Findings
1. [design] Permanent Monotonic API Naming, Uncurated PRONOM Batch Metadata, & Direct Conflicts with #1625 / #1630
- Locations:
assets/content_types.yaml/assets/exposed_content_types.txtrust/lib/src/resolvers/magic/verifiers/category/document.rsrust/lib/src/resolvers/metadata.rs
- Issue:
- Irreversible verbose slug names in
exposed_content_types.txt: Becauseexposed_content_types.txtis append-only monotonic, all 1,697 labels become permanent enum variants across Rust (ContentType), Python (ContentTypeLabel), and TypeScript (ContentTypeLabel). Several dozen PRONOM-imported entries slugify full English titles (including redundant_file,_format, and duplicated extension words) instead of Magika's concise canonical style—e.g.chemstation_gas_chromatography_mass_ms,superscape_virtual_reality_format_svr,zoombrowser_ex_thumbnail_cache_info,dna_sequence_chromatogram_file_scf,blitz3d_file_format_b3d(vsb3d/blitz3d),haiku_vector_icon_format_hvif(vshvif),ros_bag_format(vsrosbag),xar_image_format(vsxara),bim_metadata_file,yglf_file,zisofs_file. - Batch misassignment to
group: "document"&category/document.rs:groupinassets/content_types.yamlwas mapped 1:1 from the fixture/verifier directory, and ~35+ non-document PRONOM formats were placed intodocument.rs/group: "document"—even when their ownmime_typeisimage/*(atari_mppimage/x-atari-mpp,g9b_bitmapimage/x-g9b,gx2_bitmapimage/x-gx2,leadtools_cmpimage/x-leadtools-cmp,spritepad_spdimage/x-spritepad-spd), or when they are audio (asylum_music_format_amf,interleaved_adx_audio_aix), 3D geometry (blitz3d_file_format_b3d,powervr_object_data_pod,superscape_virtual_reality_format_svr), archives/disk images (mar_archive_mac,advanced_forensic_format_aff), or databases (quicken_3_database_file_qst,infofile_flr,portable_database_pdb). - PRONOM/LoC IDs baked into
TypeInfo::description: 63 added entries append(..., PRONOM fmt/..., LoC fdd...)directly intodescriptioninassets/content_types.yaml(e.g.caf,cdx,ecw,mxmf,asksam,psf,sff, plus 50+ entries indocument), whereasmainhas 0 such descriptions and tracks registry IDs inrust/lib/src/resolvers/metadata.rs(#1618 / #1624). - Over-escaped backslashes in YAML descriptions: 12 entries quadruple-escaped backslashes in YAML (
amd_microcodeDMA\\\\0,git_pack_idx\\\\xFFtOc,gnunet_gnd,iwlwifi_ucode,kindle_drmion,nintendo_u8,openssh_krl,openzim_zim,quartus_pof,serpent_stone,shinmera_sf3,student_writing_center,zucchini_patch), rendering literal double-backslashes (DMA\\0,\\xFFtOc) inTypeInfo::descriptionandwebsite-ng/src/content/docs/content-types/main.md. - Direct validation conflict with open PR
#1625(and merge overlap with#1630):wcxsetsmime_type: "text/x-wildcat-wcx"withis_text: false, and 206 added entries usegroup: "database"(108) orgroup: "geometry"(98)—all of which#1625's updatedscripts/sync_kb.pyexplicitly rejects (text/*requiresis_text: true, anddatabase/geometryare removed fromVALID_GROUPS).#1630also independently addshex2bin!and overlapping04 00 00 00/00 00 02 00dispatch logic.
- Irreversible verbose slug names in
- Two-Track Guidance:
- Option A (Recommended Architectural Path): Rebase after
#1625and#1630merge, curate the permanent label names and category/group assignments first, move the 63 PRONOM/LoC IDs fromdescriptionintorust/lib/src/resolvers/metadata.rs, and split this 1,698-format expansion into smaller category- or tier-scoped PRs (with an automated Monte Carlo random/sparse/UTF-8 false-positive test inrust/lib) so human review can verify every permanent label and format spec. - Option B (If keeping a single batch PR): Before merging, audit and rename the verbose PRONOM-slugged labels while they are still pre-merge, move non-document formats out of
document.rs/group: "document", stripPRONOM fmt/...fromcontent_types.yamldescriptions (or move tometadata.rs), fix the 12 double-escaped descriptions, fixwcx(application/x-wildcat-wcxoris_text: true) +VALID_GROUPSalignment with#1625, and add automated random/UTF-8/sparse-binary false-positive tests inrust/lib.
- Option A (Recommended Architectural Path): Rebase after
2. [high] Unchecked 64-Bit u64 & 32-Bit (wasm32) usize Addition Overflows (Debug Panics + Release Wraparound False Positives)
- Locations:
rust/lib/src/resolvers/magic/verifiers/category/archive.rs:1740(verify_criware_cpk)rust/lib/src/resolvers/magic/verifiers/category/storage.rs:516(verify_android_ota)rust/lib/src/resolvers/magic/verifiers/category/system.rs:4326(verify_sff)rust/lib/src/resolvers/magic/verifiers/category/archive.rs:5354-5357(verify_unity_webdata)rust/lib/src/resolvers/magic/verifiers/category/crypto.rs:359,363&verifiers/mod.rs:39-52(verify_kerberos_kirbi/parse_asn1_ber_len)rust/lib/src/resolvers/magic/verifiers/category/system.rs:758(verify_amd_cpu_microcode),archive.rs:3460(verify_mpq),executable.rs:1974(verify_playstation_psp_pbp)
- Explanation & Verified Triggers:
- 64-bit panics & release wraparound false positives (all three confirmed panicking with
MAGIKA_STATUS_PANICin debug builds and falsely matching in release builds):verify_criware_cpk(archive.rs:1740):utf_size = le64(prefix, 8)?->16 + utf_size <= size. Inputb"CPK \x00\x00\x00\x00\xf0\xff\xff\xff\xff\xff\xff\xff@UTF" + [0; 44](64B) panics in debug and wraps16 + 0xFFFF_FFFF_FFFF_FFF0 == 0 <= 64->Some(Label::Cpk)in release.verify_android_ota(storage.rs:516):manifest_size = be64(prefix, 12)?->manifest_size + 20 <= size(also missingstarts(prefix, b"CrAU")). Inputb"CrAU\x00\x00\x00\x00\x00\x00\x00\x02\xff\xff\xff\xff\xff\xff\xff\xf0" + [0; 44]panics in debug and wraps to4 <= 64->Some(Label::AndroidOta)in release.verify_sff(system.rs:4326):index_offset = be64(prefix, 8)?->index_offset + index_length <= size. Settingindex_offset = 0xFFFF_FFFF_FFFF_FFF0andindex_length = 16on a 64-byte.sffheader panics in debug and wraps to0 <= 64->Some(Label::Sff)in release.
- 32-bit (
wasm32)usizeoverflows & broken guard:
4.verify_unity_webdata(archive.rs:5354-5357): evaluatesheader_len >= name_start + first_name_lenbefore(1..=256).contains(&first_name_len)(overflowing 32-bitusizewhenfirst_name_len >= 0xFFFF_FFE0), and|| size <= 4096on line 5357 disables thefirst_off + first_size <= sizecheck on all files<= 4 KiB.
5.verify_kerberos_kirbi(crypto.rs:359,363):parse_asn1_ber_lenaccepts 4-byte BER lengths (0x84, up to0xFFFF_FFFFusize), soseq_off + app_content_lenandseq_len_bytes + 1 + seq_content_lenoverflow 32-bitusize.
6.verify_amd_cpu_microcode(system.rs:758,CONTAINER_HDR_LEN + eq_len + 8wheneq_len = 0xFFFF_FFF0),verify_mpq(archive.rs:3460,header_offset + 32whensize > 4 GiB), andverify_playstation_psp_pbp(executable.rs:1974,sfo_offset + 4whensize > 4 GiB) similarly overflow 32-bitusize.
- 64-bit panics & release wraparound false positives (all three confirmed panicking with
- Fix: Use
checked_addonu64(16u64.checked_add(utf_size).is_some_and(|e| e <= size), etc.), boundfirst_name_len/eq_lenbefore adding constants (and drop|| size <= 4096inverify_unity_webdata), and returnOption<(usize, u64)>fromparse_asn1_ber_len.
3. [high] verify_ansi_csi_art Tautology Misclassifies Colored Terminal / CI Logs (cargo, git diff, ls) as Binary Image Art
- Locations:
rust/lib/src/resolvers/magic/verifiers/category/image.rs:1551-1560rust/lib/src/resolvers/magic/offset_probes.rs:346rust/lib/src/resolvers/magic/mod.rs:451-453
- Explanation & Verified Trigger:
verify_ansi_csi_artchecksstarts(prefix, b"\x1b["), a secondb"\x1b["inprefix[2..64], and then callsrequire!(has_non_ascii_text_byte(prefix.get(..prefix.len().min(512))?)). Becausehas_non_ascii_text_bytereturnstruefor any byte outside0x20..=0x7E | \t | \n | \r—which includes0x1B(ESC) atprefix[0]—thatrequire!is 100% tautologicallytrue.- Verified against
libmagika:b"\x1b[1m\x1b[32m Compiling\x1b[0m magika v2.0.0 (/home/user/magika)\n"->ansi_csi_art(group: "image",is_text: false)!b"\x1b[1mdiff --git a/foo.rs b/foo.rs\x1b[m\n\x1b[1mindex 1234567..89abcdef 100644\x1b[m\n"->ansi_csi_art!b"\x1b[0m\x1b[01;34msrc\x1b[0m\n\x1b[01;32mtest.sh\x1b[0m\nCargo.toml\nREADME.md\n"->ansi_csi_art!
- (Note:
verify_perq_pos_segatexecutable.rs:1943has the same tautology becauseprefix[0..2]are< 0x20, and hundreds of other new verifiers callhas_non_ascii_text_byte(prefix.get(..N)?)over a slice that already starts with NUL/binary magic bytes.)
- Verified against
- Fix: Require genuine non-UTF-8 CP437 extended-ASCII block/box-drawing bytes (
!is_utf8_text_header(prefix, prefix.len())plus CP437 drawing bytes0xB0..=0xDF/0xFE, or a"SAUCE00"trailer inctx.tail) rather thanhas_non_ascii_text_byteon\x1b[.
4. [high] Plain ASCII, JSON, TSV & Valid UTF-8 Text False Positives (miff, pfm, phm, graoumf_gt2, manuscript, and 54 Printable-ASCII magic32 Keys)
- Locations:
rust/lib/src/resolvers/magic/magic32.rs:2074&verifiers/category/image.rs:2653-2664(verify_magick_miff)rust/lib/src/resolvers/magic/verifiers/category/image.rs:2982-3108(verify_pfm,verify_phm)rust/lib/src/resolvers/magic/verifiers/category/audio.rs:2461-2469(verify_graoumf_tracker_module)rust/lib/src/resolvers/magic/verifiers/category/document.rs:1303-1313(verify_lotus_manuscript)- 54 printable-ASCII
magic32keys guarded solely byhas_non_ascii_text_byte(e.g.document.rs:1910.scf,image.rs:2757MSID/msid,archive.rs:2346DGCA/GCA0,archive.rs:1923drpm/DLT3,system.rs:5532HDR2,executable.rs:857MTLB,database.rs:2659PWS3,audio.rs:3721NED:,audio.rs:4354Ptf/ptf,audio.rs:5360TFMX/tfmx, etc.)
- Explanation & Verified Triggers:
- 2-space JSON stolen by
miff(magic32.rs:2074):&[0x7B, 0x0A, 0x20, 0x20]isb"{\n "(standard 2-space pretty-printed JSON, whichresolvers.rs:54also expands to 64 KiB!). Every 2-space JSON file now scans up to 64 KiB forb"id=ImageMagick"at Tier 1, and valid JSON{\n "html": "<p class=\"x\">",\n "sig": "id=ImageMagick"\n}\nis misclassified asmiffinstead ofjson. - 100% printable ASCII text stolen by
pfm,phm,graoumf_gt2, andmanuscript(all verified live):b"PF\n10 20 30\nPlain ASCII text table\n"->pfm;b"PH\n 1 2 . Plain ASCII notes here\n"->phm(scale parser accepts bare"."or"0"and never checks binary float raster payload orsize == hdr + w * h * ch * {4,2}).b"GTK\t3.24.41\tGNOME Toolkit cross-platform widget library for Linux desktops\n"->graoumf_gt2((1..=9).contains(&u8_at(prefix, 3))accepts0x09 == '\t', matching TSV rows starting withGTK\torGT2\t!).b"*R1\r\nV1 1 0 DC 5\r\nR1 1 0 1k\r\n.END\r\n"(SPICE netlist / CRLF list) ->manuscript.
- Valid UTF-8 text/code stolen by
has_non_ascii_text_byteacross 54 ASCIImagic32keys:has_non_ascii_text_bytereturnstrueon any byte>= 0x80, which includes every valid UTF-8 multibyte character (—,é,“, CJK). Thus CSS".scf { /* — */ color: red; }"matchesdna_sequence_chromatogram_file_scf, French prose"DGCA — résumé of French civil aviation guidelines (2026)\n"matchesgca,"MSID — Mobile Station ID\n"matchessid(where|| has_non_ascii_text_byteinimage.rs:2769bypasses the version check!),"HDR2 — ..."matchesxiaomi_hdr,"NED: “I don’t think so...”"matchesned, etc.
- 2-space JSON stolen by
- Fix:
- Remove
b"{\n "frommagic32.rs(or verify{ ... }closes beforeid=ImageMagickand reject JSON"key":syntax). - Validate real binary header fields on
pfm/phm(valid float + raster size/binary bytes),graoumf_gt2(GT2/GTK header fields, where GT2 version is1..=5, not\t),manuscript(\directives),.scf(128B Staden header),MTLB(le64(16) == Some(size)),mrsid(drop|| has_non_ascii_text_byte), etc., and use!is_utf8_text_header(prefix, prefix.len())instead ofhas_non_ascii_text_bytewhenever guarding printable-ASCII magics against text.
- Remove
5. [high] High Random & Sparse-Binary False-Positive Rates in magic16.rs & Headerless offset_probes.rs (Plus cpio Spec Bug)
- Locations:
magic16.rs+ verifiers:executable.rs:2095(verify_tds),archive.rs:3316(verify_lzsa_compressed),archive.rs:4065(verify_pea_archive),archive.rs:1690(verify_cpio_binary),archive.rs:3231(verify_lzf)offset_probes.rs+ verifiers:audio.rs:2363(verify_game_music_creator),storage.rs:1498(verify_simh_tape),system.rs:4036(verify_realtek_wifi_firmware),audio.rs:730(verify_ac1d_packer),executable.rs:1391(verify_hp2100_abs),bytecode.rs:1364(verify_v8_bytecode)
- Empirical Evidence (1.3M-buffer Monte Carlo test on release
libmagika):- On 1,000,000 uniform random buffers, newly added verifiers produced 25 false positives (
tds: 18,lzsa: 6,lzf: 1):verify_tds(executable.rs:2097): checks only the 2 bytesFB 52+size >= 16(87.2%conditional hit rate -> 1 in 75,000 random files!).verify_lzsa_compressed(archive.rs:3323): when(flags & 0x18) == 0 && (flags & 0xE0) >= 0x20(21.9%of bytes; LZSA only defines versions1and2, i.e.0x20 | 0x40),blk1_lenandsizeare completely ignored (1 in ~300,000 random files!).verify_pea_archive(archive.rs:4069): checks onlyEA 01 [00|01]+size >= 10(21.8%ofEA 01inputs, including x86 16-bitJMP ptr16:16stubs; ignores@3..10header and"POD\0"at@10).verify_lzf(archive.rs:3231): missingstarts(prefix, b"ZV"), never checkschunk_end <= size(b"ZV\x00ABCD"of 7 B matches withus = 16,706 > 7!) or next"ZV"chunk header.verify_cpio_binary(archive.rs:1692-1699): checks onlyC7 71 00 00/71 C7 00 00(h_dev == 0), which both false-positives on 15.6% of sparse71 C7/C7 71buffers (and x86mov [rcx+0], imm32) and falsely rejects almost all real Unix/Linuxcpio -o -H binarchives whereh_dev = st_dev != 0(leavingmagic16.rs:122-123completely dead sincemagic32.rsalready claimsC7 71 00 00/71 C7 00 00)!
- On 300,000 sparse binary structs, newly added
offset_probes.rsverifiers produced 42 false positives (game_music_creator: 25,simh_tap: 11,realtek_wifi_fw: 3,hp2100_abs: 2,gt_game_systems_dux: 1):verify_game_music_creator(audio.rs:2363): any>= 1,468B zero-filled buffer with one non-zerou16sample length and@243 in 1..=100matches (0.is_multiple_of(1024)passes all zero pattern offsets; sample/pattern byte sum vssizeis unchecked).verify_simh_tape(storage.rs:1498): accepts[N, ..., N, 0](SIMH_TAPE_MARK == 0), skipssimh_record_endandlen <= MAX_SIMH_RECORD_LENwhen record 2 exceedsprefix.len(), and misclassifies 68-byte BOM-less UTF-32LE plain text" hello world!\n"assimh_tap!verify_realtek_wifi_firmware(system.rs:4054, branch 1b): only ~37 bits of constraint (@32..36 == [0xFF, 1..=16, 0, 0],@9 in 1..=8,@5 <= 16) with no chip ID or section-size sum check.verify_ac1d_packer(audio.rs:730):@0 < 0x20(allowing0, invalid in AC1D),@2..4 == 0xAC1D, andbe32(4) < size(0 bits on zeroed@4..8or any file>= 4 GiB-> 19 bits total!).verify_v8_bytecode(bytecode.rs:1364):@1 in 1..=15,@2..4 == [0xDE, 0xC0](20 bits) without checking V8'sheader_size + payload_length == size.
- On 1,000,000 uniform random buffers, newly added verifiers produced 25 false positives (
- Fix: Tighten each verifier with its format's structural invariants (
hdr_cpiomode/namesize/NUL-terminated path + filesize forcpio; TD16 symbol/pool header fortds; LZSA v1/v2 + bounded block chain +00 00 00EOD; PEA"POD\0"stream header; LibLZF chunk closure; GMC pattern+sample size accounting; multi-record + non-UTF-32LE + non-zero payload invariants forsimh_tap; rtw89 chip ID + section lengths; AC1D sample/pattern pointer tables; V8payload_lengthcheck).
6. [high] PREFIX_LIMIT = 4096 Truncation Bugs (verify_innodb_tablespace Dead on Real 16 KiB MySQL .ibd Files, Plus 5 Unreachable/Truncated Paths)
- Locations:
rust/lib/src/resolvers/magic/verifiers/category/database.rs:2126(verify_innodb_tablespace)rust/lib/src/resolvers/magic/verifiers/category/system.rs:3070-3073(verify_mediatek_signed_image)rust/lib/src/resolvers/magic/verifiers/category/system.rs:3804-3812(verify_qca_bt_tlv)rust/lib/src/resolvers/magic/verifiers/category/document.rs:2616-2618(verify_turbopower_tphelp2)rust/lib/src/resolvers/magic/verifiers/category/crypto.rs:446(verify_supp_510_pkg)rust/lib/src/resolvers.rs:60vsverifiers/category/archive.rs:5398(verify_unreal_uz2)
- Explanation & Verified Trigger:
verify_innodb_tablespace(database.rs:2126): Default MySQL/MariaDB.ibdfiles usepage_size = 16,384bytes and start with a non-zero 4-byte page checksum (FIL_PAGE_SPACE_OR_CHKSUMat@0..4). Thusresolvers::identifycapsprefix.len()atPREFIX_LIMIT = 4096, and line 2126 (be32(prefix, page_size - 4) == Some(lsn as u32)at@16380) always returnsNone.- Why the fixture test missed this:
tests_data/resolvers/fixtures/database/innodb_tablespace.ibd(131,072B) had@0..4zeroed to00 00 00 00during hollowing, which accidentally triggered ISO-9660'ssize >= 0x8006 && p.starts_with(b"\0\0\0\0")64 KiB read inresolvers.rs:55! Patching@0..4of that fixture toDE AD BE EFimmediately causesidentifyto returnunknown(verified live).
- Why the fixture test missed this:
verify_mediatek_signed_image(system.rs:3070): Checksprefix.len() >= 0x4048(16,456 > 4096) with no 64 KiB extension forb"BFBF" | b"SSSS"inresolvers.rs— dead branch.verify_qca_bt_tlv(system.rs:3805):require!(pos + 12 <= prefix.len())inside thewhile pos < prefix.len()loop returnsNoneinstead ofbreaking when a >4 KiB NVM file has a tag straddling byte4096.verify_turbopower_tphelp2(document.rs:2616) &verify_supp_510_pkg(crypto.rs:446): Both allow table sizes that pushrec_start/cert_offpast4096(highest <= 4096,count <= 4096), then unconditionally fail whenrec_start + 6 > prefix.len()orcert_off + 6 > prefix.len().verify_unreal_uz2(resolvers.rs:60vsarchive.rs:5398):verify_unreal_uz2accepts any valid zlib CMF (0x08..=0x78), whereasresolvers.rs:60only extendsprefixto 64 KiB whenp[8] == 0x78.
- Fix: Guard
be32(prefix, page_size - 4)inverify_innodb_tablespacewithpage_size <= prefix.len()while checking page-0 invariants inside@0..112(FIL_PAGE_PREV == 0xFFFF_FFFFat@8..12,FIL_PAGE_NEXT == 0xFFFF_FFFFat@12..16,@26..34 == [0; 8],FSPlist base nodes); fix the4096boundary handling in the other 4 verifiers and alignresolvers.rs:60withis_valid_zlib_header.
7. [medium] Metaformat Precedence Violations (asn1, isobmff, ar) & < 256-Byte ASN.1 DER Bug
- Locations:
rust/lib/src/resolvers/magic/verifiers/mod.rs:19-22(policy)network.rs:257-267(verify_tls_session_net443) &system.rs:3553-3563(verify_pkcs15_ky) +offset_probes.rs:446,448crypto.rs:355-375(verify_kerberos_kirbi),crypto.rs:323-334(verify_jumbf_c2pa),video.rs:609-622(verify_redcode_r3d_offset),archive.rs:5780-5797(verify_zos_ebcdic_ar)
- Explanation:
verifiers/mod.rs:19-22states that any subformat ofar,asn1,isobmff, etc. MUST live inverifiers/meta/<metaformat>.rsrather thancategory/. Placingverify_tls_session_net443andverify_pkcs15_kyincategory/+offset_probes.rs(@4..8) forced both to hardcodeu8_at(prefix, 1)? == 0x82(2-byte DER length, valid in DER only for>= 256-byte payloads; both fixtures use illegal30 82 00 00headers!), rejecting valid< 260-byte30 81 <len>/ short-form DERSSL_SESSIONtickets and PKCS#15TokenInfofiles. Additionally,verify_tls_session_net443hardcodes TLS0x0304+ cipher0x1301(TLS_AES_128_GCM_SHA256), rejecting TLS 1.2 and other TLS 1.3 cipher suites. - Fix: Move
verify_tls_session_net443andverify_pkcs15_kyintoverifiers/meta/asn1.rsusingread_tlv(broadeningSSL_SESSIONprotocol/cipher validation and fixing the two30 82 00 00fixtures), and consolidateverify_jumbf_c2pa/verify_redcode_r3d_offset(meta/isobmff.rs) andverify_zos_ebcdic_ar(meta/ar.rs).
8. [medium] Unvalidated 4-Byte Magics, Discarded Checks, Dead/Missing Dispatch Arms, & >= 4 GiB Truncations
- Locations & Details:
- Zero-check / discarded-field verifiers:
document.rs:973-975(verify_dos_eps): checks 0 bytes ofprefix(size >= 30 && prefix.len() >= 30), missing bothstarts(prefix, &[0xC5, 0xD0, 0xD3, 0xC6])and DOS EPS offset/length validation (ps_off >= 30,ps_off + ps_len <= size).image.rs:3751-3759(verify_sunras): readslet _ = be32(prefix, 4/8/12/20)?;and discards all four fields without checking width/height (> 0), depth (1|4|8|16|24|32), or type (0..=5 | 0xFFFF).document.rs:1000-1007(verify_express_publisherbare0xCAFEBEEF),document.rs:2388-2395(verify_screenwriter"SCRI"+ any NUL in4..16),system.rs:2487-2496(verify_java_webstart_idx6-byte numeric check), plus bare 4-byte magics inarchive.rs:1989(ecm),archive.rs:5715(yz1\x01),document.rs:872(wpsplus),document.rs:1618(evy),document.rs:2066(MAR\x80),document.rs:2170(CE 19 CE 19),document.rs:2238(vips_image_v).- ~25 verifiers omit
starts(prefix, MAGIC)insideverify_*(e.g.keepass,tensorstore_ocdbt,ruby_yarb,os2_help_inf,linux_psf1/psf2,cri_hca,mo3,godot_pck,valve_vpk,unreal_package, etc.), leaving@0..4untracked bysuper::probe.
- Dead / mismatched dispatch arms:
magic16.rs:187dispatches&[0x00, 0xFE]toverify_ms_works_dos_wps, which hardcodesu8_at(prefix, 0)? == 0x01atdocument.rs:1528.magic16.rs:194dispatchesb"S."toverify_palladix_pcs(audio.rs:3979-3993), which has no"S."branch and unconditionally returnsNone.magic32.rs:1316-1317dispatchesb"JISO" | b"ZISO"toverify_cso_container(storage.rs:758), which hardcodesstarts(prefix, b"CISO").- Conversely, implemented branches in
system.rs:1430(b"BIC "),image.rs:3213/archive.rs:4664(b"GBIX"),network.rs:241(b"NETX"),database.rs:2664(b"PWS2"), andarchive.rs:5774(b"\xFE\x07\x01") have no matching dispatch keys inmagic32.rs/magic16.rs.
size as u32/size as usizetruncations on>= 4 GiBfiles:audio.rs:2224(verify_fm_towns_euphony),audio.rs:5579-5580(verify_voodoo_vss),bytecode.rs:1250(verify_torquescript_dso), andfont.rs:955(verify_riscos_outlines) castsize as u32(wrapping at4 GiBon all platforms);storage.rs:1662(verify_ucsd_vol) andmagic/mod.rs:444,461(is_utf8_text_header/is_mostly_printable_header) castsize as usize(wrapping onwasm32).
- Zero-check / discarded-field verifiers:
9. [medium] tests_data/resolvers/fixtures/ Adds 23.3 MB of Uncompressed Zero-Filled Files to Every Checkout
- Locations:
tests_data/resolvers/fixtures/(29 files>= 64 KiB, includingsystem/ps2_vmc.ps2=8,388,640B [32 non-zero bytes],archive/cigames_dpk4.dpk=3,669,996B [10 non-zero bytes],storage/alto_dsk.dsk=2,601,648B [11 non-zero bytes],executable/hermes.hbc=962,704B,storage/c1581_d81.d81=819,200B,serialization/unreal_usmap.usmap=640,482B,video/wink_wtp.wtp=591,680B,archive/sega_afs.afs=524,320B,bytecode/quake3_qvm.qvm=467,116B) - Explanation: Although zlib packs zero runs tightly in
.git, everygit checkout, worktree, CI job, and source archive materializes 23.29 MB of zero-padded files on disk (94× the existing 310 fixtures'247 KB, and in sharp contrast to#1630's8.5 KBtotal across 30 fixtures). - Fix: For formats where offsets/lengths are header fields (
cigames_dpk4,hermes,unreal_usmap,wink_wtp,sega_afs,quake3_qvm, etc.), craft minimal< 4 KiBfixtures with small offsets; for fixed-disk-size formats (ps2_vmc,alto_dsk,c1581_d81,ibm_3740), either constructvec![0u8; EXACT_SIZE]in unit tests (asresolvers.rs:554and675already do forIsoandClarionMem) or store tiny run-length specs liketests_data/resolvers/regressions.json.
10. [nit] Commit Bisectability, PR Description Drift, & Minor offset_probes.rs Inline Pre-Guards
- Commit order (
dcdd6eb6before6e550153): Commit 2 (rust/lib) uses 1,697ContentType::*variants that are not generated inrust/lib/src/content.rsuntil Commit 3 (chore), sodcdd6eb6does not compile standalone duringgit bisectunless squash-merged. - PR description drift: Still mentions 3 commits (now 4 with
3d53eb00) and omits mentioning theCompactContentTypeInfolabel-slot change (${ContentTypeLabel}->stringfor TS2590) inscripts/sync_kb.py:2061. - Stage 4 pre-guards (
offset_probes.rs:822,828): Addingsize == 256_256inline beforeverify_ibm_3740(matchingverify_xerox_alto_diskat line 646) andsize >= 2739 && (size - 1587).is_multiple_of(1152)beforeverify_hsc_trackeravoids enteringsuper::probeon every>= 1.5 KiBmiss.
3. Questions / Things to Verify
- Corpus evaluation (
MAGIKA_RULES_DATASET): Wascargo test --release --lib resolvers::tests::dataset -- --ignored --nocapturerun against the full evaluation dataset manifest with all 2,008 resolvers active, and what were the validated hit / false-positive / unverified disagreement counts and mean scan latency? - Staging & coordination with
#1625and#1630: Should#1625(KB schema/group tightening) and#1630(30 high-cardinality resolvers) merge first, followed by rebasing/splitting this PR to adopt#1625's 13-group taxonomy and curated label names before locking 1,697 labels intoexposed_content_types.txt?
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Expand Magika's native Rust format resolvers (
rust/lib/src/resolvers/) with deterministic structural verifiers for 1,698 standalone binary formats (1,697new content types plus existing catalog-only entrytfrecord), bringing resolver coverage from 310 → 2,008 content types (480 → 2,177KB entries;404 → 2,102exposed labels).ML model predictions (
standard_v3_3),VETOS, existing resolvers, and PRONOM/LoC metadata are untouched.What changed
rust/lib/src/resolvers/):hex2bin!,le/be*_bytes!,ebcdic_bytes!) and shared zlib / ASN.1 BER length helpers (zero new crate dependencies).magic32.rs) and 62 Tier-2 (magic16.rs) O(1) prefix dispatch entries across 15 category modules (audio: 336,archive: 284,system: 275,document: 143,image: 121,database: 108,model3d: 98,storage: 80,executable: 68,bytecode: 50,serialization: 39,font: 38,video: 34,crypto: 16,network: 8).offset_probes.rsas a 4-stage O(1) dispatch (prefix.len() >= 256fixed-offset switches →>= 124-byte offset probes →>= 4multi-byte probes → rare/headerless fallbacks gated by fast byte/size pre-filters).resolvers.rsfor multi-chunk Unreal Engine 2.uz2archives so chunk 2 is verified beyondPREFIX_LIMIT.tests_data/resolvers/fixtures/):310 → 2,008, 1:1 within_resolverscontent types).1,697entries toassets/content_types.yaml, updatedscripts/sync_kb.pyto wrap >100-column generated Rust match arms forrustfmt, and regenerated all KB, Rust, C FFI, Python, JS/TS, and website artifacts viascripts/sync_kb.py.Review guide
The branch is split into 3 commits mirroring
#1606:tests_data: 1,698 binary fixtures.rust/lib: hand-written resolver code, O(1) dispatch, and tests.chore:assets/content_types.yaml,scripts/sync_kb.py, and regenerated bindings/docs.Verification
uv run scripts/sync_kb.py --self-test && uv run scripts/sync_kb.py --check(53/53, all 12 artifacts in sync, frozen snapshots unchanged)cd rust/lib && ./test.shon bothstableandnightly(34/34tests including all2,008fixtures and15,169regression cases,rustfmt,clippy --deny=warnings, nightlyRUSTDOCFLAGS=--deny=warnings cargo doc)cd rust/ffi && ./test.sh,cd rust/pyo3 && ./test.sh,cd rust/cli && ./test.shcd python && uv lock --check && uv run ruff check && uv run ruff format --check && uv run ty check && uv run pytest tests -m "not slow"+ CLI/module quick tests (41 passed)cd go && go test ./...uv run scripts/check_copyright.py && uv run scripts/check_documentation.py