dm2-cli: auto-detect chains swallow typed parse errors — corrupt files of recognised families report generic 'could not identify' #206
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
The CLI's format auto-detection swallows the useful diagnostics.
dm2 info,dm2 extract, and (partially)dm2 verifyprobe formats withif let Ok(…)chains (crates/dm2-cli/src/commands/{info.rs,extract.rs}), so a corrupt file of a recognised family falls through every probe and dies with a generic message:0x8000signature but a truncated payload region produces the precise typed errorPayloadCoverageMismatch { computed, file }insideArchive::parse— which the chain discards, reporting only "could not identify " / "not a recognized archive format".0x6160magic but an out-of-bounds hunk (TruncatedHunk { .. }discarded), or a MacBinary-wrapped fork with a bad AppleDouble version.For a tool whose users routinely feed it half-understood dumps, "the file matched graphics.dat's signature but failed to parse: " is the difference between a bug report and a shrug.
Fix direction
Two-stage dispatch: a cheap magic pre-check per family (graphics.dat
sig & 0x8000, FTL0x6160, HMPHMIMIDIP, MacBinary/AppleDouble sniff), and when the magic matches but the full parse fails, surface that family's parse error instead of continuing the chain. Families without a magic (dungeon.dat, saves) keep the current plausibility-probe behaviour.verifyalready reports per-family results and needs only the graphics/FTL arms adjusted;infoandextractgain the most.Reopening: the fix (
51170f7a) closed this for the magic-bearing families (graphics.dat, FTL, resource forks) but the savegame family was left with the original swallow-the-error behaviour, so the exact symptom this issue describes is still reproducible for saves.The fix commit message states "Magic-less families (dungeon.dat, saves) already propagated post-probe errors and are unchanged." That is not true for saves.
detect_save(crates/dm2-cli/src/commands/mod.rs:59-79) runs the full parse and discards the typed error with.ok():Unlike the
try_parse_graphics/try_parse_ftl/try_open_resource_forksiblings (allResult<Option<_>>, so a fingerprint match plus a parse failure surfaces the typed error),detect_savefolds "recognised family, corrupt" into the sameNoneas "not a save at all."Reproduction (the header, which carries the
w_timer_flagfingerprint, stays intact):The library already computes the precise cause inside
SaveFile::parse(e.g. "sksave truncated in map_table: need N bytes, got M", crates/dm2-saves/src/sksave.rs:373-382); the CLI throws it away. Thedm2 save show/champion/global/party/inventorysubcommands route throughload_save(commands/save/mod.rs:138-149) and report the same generic "{file} is not a recognised DM2 savegame" for the same input.Fix direction (unchanged from the original): make
detect_savereturnResult<Option<(...)>>like itstry_parse_*siblings — keep the cheap header /looks_like_*probe as the family gate, and once a variant fingerprint matches, propagateSaveFile::parse'sErrinstead of.ok()-ing it; update the four call sites to?the outerResult.