xtask: bound policy file reads and report read errors #3026

Open
github-bot wants to merge 1 commit from github-bot/gh-3026 into main AGit
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 03:48 UTC · original
fuzeofficlal:fix/xtask-policy-bounded-read-and-errors → main · +258 −22 · 1 files · 1 commits · open

Summary

xtask::policy::run previously loaded every checked file completely into memory (std::fs::read in working-tree mode and git show :<path> in --staged mode) and silently skipped any file whose read or git show failed:

  • An accidentally dropped or staged large asset (multi-GB game archive, dump, etc.) is read completely into memory before check fails on the 512 KiB limit, risking OOM or a long hang in cargo xtask policy / .githooks/pre-commit.
  • Non-NotFound working-tree read errors (unreadable files, directories/gitlinks) and failing staged lookups (such as staged gitlinks 160000 where git cat-file blob fails) were silently ignored instead of being reported as policy violations.

Changes

  • Read at most MAX_FILE_SIZE + 1 (524,289) bytes per file into a single reused buffer via read_prefix:
    • Working-tree mode opens the file, skips only ErrorKind::NotFound (deleted tracked files), reads up to READ_LIMIT bytes, and uses file.metadata().len() to report the exact oversized file length.
    • --staged mode streams git cat-file blob :<path> and stops reading after READ_LIMIT bytes (killing/reaping the child when oversized), querying git cat-file -s :<path> only when oversized to report the exact blob length.
  • Surface non-NotFound working-tree open/metadata/read errors and non-oversized git cat-file failures as asset-policy violations instead of skipping the entry.
  • Add unit tests covering:
    • Bounded prefix reading and exact-size reporting on oversized working-tree files.
    • Skipping missing working-tree files while surfacing non-NotFound errors (directories).
    • Reading regular staged blobs, bounding oversized staged blob reads, and rejecting staged gitlinks (160000).

Verification

  • rustfmt --edition 2024 --check xtask/src/policy.rs — pass
  • cargo test --locked -p xtask — 10 passed, 0 failed
  • cargo clippy --locked -p xtask --all-targets -- -D warnings — pass
  • cargo xtask policy — asset policy: 191 files ok
**@⁠fuzeofficlal** on GitHub · 2026-11-26 03:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/3026) `fuzeofficlal:fix/xtask-policy-bounded-read-and-errors` → `main` · +258 −22 · 1 files · 1 commits · open ### Summary `xtask::policy::run` previously loaded every checked file completely into memory (`std::fs::read` in working-tree mode and `git show :<path>` in `--staged` mode) and silently skipped any file whose read or `git show` failed: - An accidentally dropped or staged large asset (multi-GB game archive, dump, etc.) is read completely into memory before `check` fails on the 512 KiB limit, risking OOM or a long hang in `cargo xtask policy` / `.githooks/pre-commit`. - Non-`NotFound` working-tree read errors (unreadable files, directories/gitlinks) and failing staged lookups (such as staged gitlinks `160000` where `git cat-file blob` fails) were silently ignored instead of being reported as policy violations. ### Changes - Read at most `MAX_FILE_SIZE + 1` (524,289) bytes per file into a single reused buffer via `read_prefix`: - Working-tree mode opens the file, skips only `ErrorKind::NotFound` (deleted tracked files), reads up to `READ_LIMIT` bytes, and uses `file.metadata().len()` to report the exact oversized file length. - `--staged` mode streams `git cat-file blob :<path>` and stops reading after `READ_LIMIT` bytes (killing/reaping the child when oversized), querying `git cat-file -s :<path>` only when oversized to report the exact blob length. - Surface non-`NotFound` working-tree open/metadata/read errors and non-oversized `git cat-file` failures as asset-policy violations instead of skipping the entry. - Add unit tests covering: - Bounded prefix reading and exact-size reporting on oversized working-tree files. - Skipping missing working-tree files while surfacing non-`NotFound` errors (directories). - Reading regular staged blobs, bounding oversized staged blob reads, and rejecting staged gitlinks (`160000`). ### Verification - `rustfmt --edition 2024 --check xtask/src/policy.rs` — pass - `cargo test --locked -p xtask` — 10 passed, 0 failed - `cargo clippy --locked -p xtask --all-targets -- -D warnings` — pass - `cargo xtask policy` — `asset policy: 191 files ok`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:26:52 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 06:17 UTC · original

Automated triage for the maintainers.

This needs the maintainer's decision. It changes xtask/src/policy.rs, the asset-policy allowlist that the pre-commit hook runs, and it changes how that tool spawns processes. --staged now streams git cat-file blob through a pipe, kills the child when a file is too big, and runs a second git cat-file -s. The new tests create temporary git repositories with git init/update-index.

From reading it, the change tightens the policy rather than loosening it. run still skips EXCEPTIONS the same way. Reads are capped at MAX_FILE_SIZE + 1. Read errors other than NotFound (and failing staged lookups such as gitlinks) are now reported as violations instead of being skipped silently. Deleted index entries are not affected, because list_files already passes --diff-filter=ACMR. I found no correctness problem. One point for the maintainer: in working-tree mode, any tracked path that cannot be opened as a file (for example a future submodule gitlink) now fails cargo xtask policy. There are none today.

CI: check passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 06:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/3026#issuecomment-7184275824) <!-- victory-triage v1 head=40d280e08b1913fff6bc9bb36196de4dcb1b829c verdict=needs-work at=2026-11-26T06:19:00Z --> Automated triage for the maintainers. This **needs the maintainer's decision**. It changes `xtask/src/policy.rs`, the asset-policy allowlist that the pre-commit hook runs, and it changes how that tool spawns processes. `--staged` now streams `git cat-file blob` through a pipe, kills the child when a file is too big, and runs a second `git cat-file -s`. The new tests create temporary git repositories with `git init`/`update-index`. From reading it, the change tightens the policy rather than loosening it. `run` still skips `EXCEPTIONS` the same way. Reads are capped at `MAX_FILE_SIZE + 1`. Read errors other than `NotFound` (and failing staged lookups such as gitlinks) are now reported as violations instead of being skipped silently. Deleted index entries are not affected, because `list_files` already passes `--diff-filter=ACMR`. I found no correctness problem. One point for the maintainer: in working-tree mode, any tracked path that cannot be opened as a file (for example a future submodule gitlink) now fails `cargo xtask policy`. There are none today. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-26 04:40 UTC · original · approved these changes

LGTM — READ_LIMIT caps staged reads, errors surface as violations instead of silent skips, buffer reuse avoids per-file allocation.

**@⁠kotekompotek** on GitHub · 2026-11-26 04:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/3026#pullrequestreview-6068636582) · **approved these changes** LGTM — READ_LIMIT caps staged reads, errors surface as violations instead of silent skips, buffer reuse avoids per-file allocation.
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-26 20:40 UTC · original

Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head 40d280e (on its base 63bcca4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 870 passed, 0 failed, 10 ignored.
  • The new tests ran and passed: worktree_reads_only_a_bounded_prefix_of_an_oversized_file, worktree_skips_missing_files_and_surfaces_other_read_errors, staged_reads_regular_blobs_and_rejects_gitlinks, staged_reads_only_a_bounded_prefix_of_an_oversized_blob.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-26 20:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/3026#issuecomment-7202952056) Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head `40d280e` (on its base `63bcca4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **870 passed, 0 failed, 10 ignored**. - The new tests ran and passed: `worktree_reads_only_a_bounded_prefix_of_an_oversized_file`, `worktree_skips_missing_files_and_surfaces_other_read_errors`, `staged_reads_regular_blobs_and_rejects_gitlinks`, `staged_reads_only_a_bounded_prefix_of_an_oversized_blob`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3026/head:github-bot/gh-3026'
git switch 'github-bot/gh-3026'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3026'
git switch 'github-bot/gh-3026'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3026'
git switch 'github-bot/gh-3026'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3026'
git switch 'main'
git merge --squash 'github-bot/gh-3026'
git switch 'main'
git merge --ff-only 'github-bot/gh-3026'
git switch 'main'
git merge 'github-bot/gh-3026'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3026
No description provided.