CLI: xcl rpf and xcl shaders silently ignore unknown options and mistyped values, and still exit 0 #2266
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl#2266
Loading…
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?
@itsonewi on GitHub · 2026-11-25 11:53 UTC · original
Summary
xcl rpfandxcl shadersread their options by position and drop whatever they do not recognise, so a typo or a forgotten value changes what the command does and the command still exits 0.xcl disasmis the one that reports it, so the fix has a precedent right next to the bug.crates/xcl/src/rpf.rs(1a0bbe3, line 100):crates/xcl/src/shaders.rs(line 799, and again at 1996 withu64):crates/xcl/src/disasm.rs(line 17) does it the other way:What it does to a user
xcl rpf pkg.rpf --extract- the value is forgotten.opt()returnsNone,extractisNone, so nothing is extracted; the record listing prints and the exit code is 0. The user concludes the record is not in the archive.xcl rpf pkg.rpf --fnid foo- an unknown option is not looked at at all, so there is no filter: every record is listed, exit 0.xcl shaders pack --hash 0xZZ(line 2026,u64::from_str_radix(...).ok()) - an unparseable hash becomesNone, which means no filter: the whole corpus is translated instead of the one record. With the defaults the translator runs over the sample; with--sample 0that is a full sweep that takes hours and looks like it is working.--top abc,--threads abc,--timeout abc- all silently take the default.Nothing here is a crash; the problem is that the tool answers a different question than the one asked, quietly. For
--hashthe wrong answer is expensive.Suggested fix
One helper in
main.rs(or a smallcli.rs), used by both subcommands, modelled ondisasm::number_option:returning
2with the message on stderr, plus a pass overargsthat rejects an entry starting with-that no subcommand consumed ("unknown option: --fnid; seexcl --help"). TheOption-returning local closures then becomenumber(args, "--top")?.Not #2216
#2216 is the usage text not listing
--precompile/--pipelines, which is the opposite direction: documented flags missing from--help, not flags that are accepted and ignored.Not tested
1a0bbe3without a checkout. Each case above is a direct reading of the closure and of theopt()call sites.AI use
crates/xcl/src/rpf.rs,crates/xcl/src/shaders.rs,crates/xcl/src/disasm.rsandcrates/xcl/src/main.rson1a0bbe3and wrote this report; the human account checked the call sites before opening it.@itsonewi on GitHub · 2026-11-25 12:01 UTC · original
I checked this against the open PRs that touch the same surface, so it does not duplicate one:
crates/xcl/tests/rpf_e2e.rs) pinxcl rpfwith no arguments, a missing archive, a non-RPF9 file and an empty TOC. None of them passes a known option with a missing or unparseable value, and none passes an unknown option - which is what happens here. Whoever fixes this should add those two cases to that file rather than a new one, so the rpf CLI tests stay in one place.2for a usage or input error,3for a file that is not a PE, and an unknown command prints the usage to stdout with2.xcl rpfandxcl shadersalready print their own diagnostics to stderr with2(e.g.xcl rpf: --probe cannot be combined with --find), so the new messages should follow that and not copy the top-level usage block.@itsonewi on GitHub · 2026-11-25 15:51 UTC · original
Both #2285 and #2303 fix this, and they now conflict with each other: each creates
crates/xcl/src/cli.rsfrom scratch with a different API (aParserstruct vs. free functionstext/number/hex_u64/unknown), so whichever merges second needs a rebase, and merging both would leave two parsers doing the same job.Against what this issue asks for (stderr + exit 2, nothing silently defaulted), both are complete:
eprintln!+return 2eprintln!+return 2--flagin the value slot--hash0xoptionalu64::from_str_radix,0xoptional--top,--threads, ...)parse::<usize>0xtests/rpf_e2e.rsandtests/shaders_e2e.rscovering the cases reported herecli.rsTwo factual differences, for whoever picks one; neither is a reason to reject either PR:
Parser, so a value cannot be read twice and the option set is checked in one place. #2303 keeps the per-optionargs.iter().position(..)lookups and puts strictness around them - a much smaller diff, but the "read the same option twice" shape stays.unknown()in #2303 scans values too.args.iter().find(|a| a.starts_with('-') && !known.contains(a))walks every argument, values included, so a value that begins with a single dash is reported as an unknown option; the unit test above it comments "values are not looked at", which the implementation does not match. Values beginning with--are caught earlier bytext(), so this only bites on single-dash values. Minor, and it is the one place where the two behaviours really differ.Worth merging one and closing the other so the second author's work is not lost to a rebase.
AI use: read both patches, the current
mainofmain.rs/log.rs, andCONTRIBUTING.mdthrough the GitHub API to compare the two fixes; no code was written by an agent here and no build was run.@itsonewi on GitHub · 2026-11-25 16:01 UTC · original
Correction to my note above, and the part I got wrong: I compared the two patches without reading their conversations, which was incomplete.
#2303 had already been through an independent retest by nnonno91 of eight CLI cases (
--threads abc,--timeout abc,--only,--max-bytes x,--direct --threads abc, ... on an empty folder and on a nonexistent input), and b3IKK fixed four real holes it found at8d1544f. #2303 is now closed, so those eight verified cases should be re-run against #2285's head before it merges rather than disappearing with the branch. GustavoEllwanger's own comparison on #2285 (posted at 15:49Z, before mine) also lists two behaviours my table did not: #2285 rejects stray positional arguments, which anunknown()that only looks at--prefixed arguments cannot catch, and validates--splitas0or1instead of accepting any non-zero integer as true. Together that is a superset of what #2303 was checked against, so the closure looks right; the point is only that the eight cases should move with it.The table above stands as far as the patches go. The missing input was the review history, not the code.
AI use: read both PR threads, the patches and the current
mainthrough the GitHub API; no code was written by an agent here and no build was run.