policy: fail when staged content cannot be read #377
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!377
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/377/head"
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?
@lordon1a on GitHub · 2026-11-24 02:44 UTC · original
fix/policy-staged-read-error→main· +14 −2 · 1 files · 1 commits · closed without mergingSummary
xtask/src/policy.rslists staged files viagit diff --cached --name-only --diff-filter=ACMR -z(so deleted files are already excluded), yetrun()silently skipped any file wheregit show :<path>returned non-zero (continue; // deleted in the index), counting unreadable entries as passing the asset policy check.This change:
check_files()and bails with the file path and exit status whenevergit show :<path>fails in--stagedmode.staged_file_read_failure_is_reported) verifying that an unreadable staged path fails the check with the path named in the error.Verification
Tested on Windows 11 (
rustc 1.100.0,x86_64-pc-windows-gnullvm):cargo test -p xtask: 5 passed, 0 failed (the new test fails onmain@d2a4bae1fwhere the read failure is silently skipped).cargo clippy -p xtask --all-targets: 0 warnings.cargo xtask policy: 151 files ok (zero game data).AI-assisted.
@SkippySteve on GitHub · 2026-11-24 03:13 UTC · original
Thanks for this. The silent
continueis a real hole, and I can reproduce it. I tested on Linux (Arch, stable Rust) againstmainatd2a4bae.Tests on this branch (
4da59d1):cargo test -p xtaskpasses 5/5,cargo clippy -p xtask --all-targetsgives no warnings, andcargo xtask policyreports 151 files ok.End to end,
cargo xtask policy --stagedwith a crafted index:main160000to a commit not in this repo (vendor/blob)1 files ok(passes)Error: cannot read staged file vendor/blob (exit status: 128)POLICY: vendor/blob: a submodule: content from another repository bypasses this checkMZ\0\0under a non-UTF-8 name (bad\xff.rs)1 files ok(passes)Error: cannot read staged file bad�.rs (exit status: 128)lnk.rsreplaced byMZ\0\0(staged asT)0 files ok0 files ok(still passes)So this PR closes the first two holes. Some notes:
bail!stops at the first file. Every other problem goes intoviolationsand they are reported together. Withbail!, a commit that has an unreadable entry and a real binary shows only the first one. Pushingformat!("{path}: cannot read the staged content")ontoviolationsand continuing would fit the existing output better.exit status: 128hides the reason. AddingString::from_utf8_lossy(&out.stderr)to the message would show git's own error (bad object :vendor/blob).git show :<path>. The path comes fromfrom_utf8_lossy, so a non-UTF-8 name can never be read back by name. A gitlink has no blob to show. #246 readsgit diff --cached --raw -zinstead and fetches each entry by object id withgit cat-file blob <oid>, so no file name can break the read. It reports gitlinks and non-UTF-8 names as their own violations, addsTto the diff filter, and reads symlinks as git stores them.Overlap with #246: #246 already turns an unreadable staged entry into a violation (
read()returnsErr→violations.push), so this change is a subset of it. The two PRs also conflict textually inxtask/src/policy.rs(git merge-treereports a content conflict). If #246 lands, this PR isn't needed. If maintainers would rather take the small fix first, this one is correct as it stands, and I'd suggest note 1 before merging. Then I'll rebase #246 on top.Pull request closed