Skip to content

Bound discovered and packed shaders to their containers - #116

Open
andrewDoing wants to merge 2 commits into
DexNom:mainfrom
andrewDoing:fix/raw-shader-container-bounds
Open

andrewDoing wants to merge 2 commits into
DexNom:mainfrom
andrewDoing:fix/raw-shader-container-bounds

Conversation

@andrewDoing

@andrewDoing andrewDoing commented Nov 26, 2026 •

Copy link
Copy Markdown

Raw shader discovery currently passes the entire remaining input file as each discovered DXBC container. The translation tool consequently hashes and can dump unrelated trailing data, and the same shader can receive different hashes depending on its location.

Use the validated declared container length for discovered raw sources and share that length with warmup. Also bound valid unpacked SGD5 payloads before translation hashes and dumps them, retaining original bytes for malformed-payload diagnostics.

The CLI reported the same hash for a synthetic shader on its own and at two offsets in an archive; a matching dump contained exactly the shader's 48 bytes. A second 475-byte synthetic shader produced the same hash and dump as raw, packed, and packed with nine trailing bytes. Regressions cover both raw and packed boundaries.

Pinned Rust 1.98.1: both workspace Clippy configurations and the asset policy passed; the serial workspace suite passed with 685 passed, 0 failed, and 12 ignored using CI's software-adapter setting. No game data or gameplay run.

Thanks to @retrope13 for identifying the packed-record asymmetry. GPT-6.2 Astra implemented and tested the change.

@retrope13

Copy link
Copy Markdown

Independent hardware-GPU Windows verification and diff review of #116 (863e6faa) against main (64bd58f5): both Clippy configs, targeted debug/release tests, and full real-GPU workspace suite pass with 0 failures.

Tested

  • Hardware / Env: NVIDIA GeForce RTX 4060 Laptop GPU (8 GB, driver 32.0.16.2140), Intel Core i5-14500HX (14C/20T), 24 GB RAM, Windows 11 26H2 (build 26300.9818), pinned rustc 1.98.1 (x86_64-pc-windows-msvc), verified BCPack tables via Initialize-FormatTables.ps1.
  • Targeted tests:
    • cargo test --locked -p victory -- embedded_raw_sources_end_at_the_declared_container_size: 1 passed, 0 failed in both debug and --release.
    • cargo test --locked -p victory-shader dxbc: 2 passed, 0 failed.
  • Clippy (both CI configs):
    • cargo clippy --workspace --all-targets --locked -- -D warnings: pass (exit 0)
    • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: pass (exit 0)
  • Full workspace suite (real hardware GPU, VICTORY_TESTS_ALLOW_SOFTWARE_SKIP unset):
    • cargo test --workspace --locked --no-fail-fast -- --test-threads=1: 684 passed, 0 failed, 12 ignored.

Diff Review (64bd58f5..863e6faa)

  • Bounds safety (crates/victory-shader/src/dxbc.rs:77-80,105): Confirmed Container::parse enforces HEADER_SIZE <= total <= data.len() before returning Container { byte_len: total, .. }, so &tail[..container.byte_len] (apps/victory/src/shader.rs:50) and &bytes[..container.byte_len] (apps/victory/src/translate.rs:336) cannot panic.
  • Minor non-blocking note (apps/victory/src/translate.rs:397,440,465): Source::Raw is now bounded to container.byte_len before reaching translate(), so raw shaders hash and dump identically to warm(). However, Source::Packed (sgd5::Record::unpack) returns the full inflated record without slicing to container.byte_len: if an unpacked SGD5 record ever has trailing bytes past its DXBC container, translate() hashes &bytes at line 397 (before Container::parse at line 414) and dumps &bytes[..] at lines 440/465, whereas warm() explicitly slices &bytes[..container.byte_len] before hashing at line 336. Out of scope for raw discovery here, just noting the asymmetry in case packed records can carry trailing padding.

Not Tested

  • Live game/archive CLI runs, AMD GPUs, and the 12 #[ignore] tests.

AI disclosure: Antigravity (Gemini 4 Neon, XHigh) ran the checks, reviewed the diff, and drafted this report.

@andrewDoing andrewDoing changed the title Bound discovered raw shaders to their containers Bound discovered and packed shaders to their containers Nov 26, 2026
@andrewDoing

Copy link
Copy Markdown
Author

Thanks @retrope13 for the independent hardware verification and for catching the packed-record asymmetry. Confirmed with a valid synthetic SGD5 record: nine bytes after a 475-byte DXBC payload changed the translate hash and dump size, while warm deduplicated the same shader. Pushed a386e40 to bound valid unpacked containers before hashing and dumping; malformed payload diagnostics retain the original bytes.

Raw, packed, and padded-packed inputs now produce the same hash and 475-byte dump. Both workspace Clippy configurations and the asset policy passed; the clean serial workspace suite passed with 685 passed and 12 ignored using the CI software-adapter setting. No retail archive or gameplay was tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants