policy: fail when staged content cannot be read #377
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/377"
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?
Imported from Marvisak/VIctory. Originally posted by lordon1a on 2026-11-24T02:44:28Z.
Summary
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.
Imported from Marvisak/VIctory. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-24T02:44:42Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Imported from Marvisak/VIctory. Originally posted by SkippySteve on 2026-11-24T03:13:40Z.
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.Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T12:50:47Z.
Review: APPROVED
Tested
4da59d1on Windows 11, RTX 5070, MSVC:cargo test -p xtask5 passed, includingstaged_file_read_failure_is_reported.cargo xtask policypasses on this head (151 files).git show :<path>failures are handled. It runs no new processes.--diff-filter=ACMR, agit showfailure can't be a deletion, so failing loudly is right. Silently skipping meant a file the check couldn't read passed the asset policy.git show :<path>. There are no submodules today, but if one is added, filter mode160000out of the list rather than failing the hook.AI-assisted (Claude Code).
Pull request closed