Repository navigation
Loader: guard dir64_relocations against BASERELOC size and page+offset overflow (fixes #2411) - #2418
pushkarreddyy wants to merge 1 commit into
Conversation
DenRakEiw
left a comment
There was a problem hiding this comment.
Verified against origin/main (940d32f):
- Guarding
dir64_relocationsagainst oversizedBASERELOCdirectories andpage + offsetoverflows (#2411) is clean and well-tested. cargo test -p victory-loader: 39/39 passed (35 unit includingdir64_relocations_clamps_oversized_directory_and_overflowing_pages+ 4 integration tests).cargo clippy -p victory-loader --all-targets -- -D warnings: 0 warnings.cargo xtask policy: 183 files ok.
AI-assisted (Gemini 4 Neon).
catminou4
left a comment
There was a problem hiding this comment.
Tested locally: merged into main 940d32f, cargo test -p victory-loader --locked on macOS arm64. All 4 failures — including this PR's new dir64_relocations_clamps_oversized_directory_and_overflowing_pages — are environmental: prepare::tests parse the host's own Mach-O binary as PE ("Unknown file magic"), same as the 3 pre-existing ones on main. They can't pass off Windows by construction; #2334's #[cfg(windows)] gating already handles this class (this new test should get the same gate when it rebases past #2334). The BASERELOC guard logic itself is sound. Approving.
|
Reviewed: |
|
Thank you @kotekompotek for the review! Testers on untested Windows 10/11 and Wine/Proton configurations are welcome to verify. AI-assisted: yes (Gemini 4 Neon) |
|
Automated triage for the maintainers. Proposed close. This adds guards for cases that cannot fail in
The test's first call makes no assertion. An input that reaches a real failure here would change the verdict. This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label. Generated by Claude Code |
…C size and page+offset overflow (fixes Marvisak#2411)
…C size and page+offset overflow (fixes Marvisak#2411)
|
Closing this PR after reviewing the triage verification on
Thank you for the audit. AI-assisted: yes (Gemini 4 Neon) |
What's wrong: `victory translate --validate --jobs 16` under CrossOver crashed once in two runs inside dxil.dll's Validate (a write fault in the heap). Each worker had its own IDxcValidator, created again for every file of the walk. DXC promises that DxcCreateInstance is thread-safe and that its objects have no thread affinity (DirectXShaderCompiler Marvisak#79, Marvisak#2418), but instances share the library's global state (LLVM's pass registry, the CRT locale, the allocator), and DXC's maintainers do not promise two instances can run at the same time (#5566 was such a race between per-thread compilers on a 16-core machine). The fix: - validator.rs: LoadLibrary + DxcCreateInstance and the final Release are serialised process-wide on every host (cheap, a few per run). - Calls into dxil.dll go through a counting gate: under Wine (ntdll exports wine_get_version) one at a time; on Windows no limit, as before. VICTORY_VALIDATE_JOBS=N sets the limit on any host. - The time spent inside Validate and waiting for a turn is counted; `translate --validate` prints both, so the cost of the gate on a real run is measured, and says "(1 at a time)" when the gate is on. - translate.rs: validators go back to a pool when a file's workers end, so each is made once per run instead of once per file and worker. Translation, pipeline creation and everything else stay parallel. On this Linux host under Wine 10, Validate takes about 0.6 ms for a 3 KiB program and 16 workers get only about 4x from running it in parallel (8 workers about 2.7x), so the gate costs at most the sum of the validation times; 240,000 concurrent validations of our own programs with 16 workers did not reproduce the crash here, so the Wine limit rests on the Mac run. Tests: emit::validator::tests::validators_on_several_threads_agree (8 threads making, using and releasing validators at once, each signed container equal to a single caller's) and a_gate_admits_at_most_its_limit; emit::own, split_tests, stride_tests, memory_tests, resource and dispatch_threads pass under Wine with dxil.dll 1.9.2609. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes #2411.
Root Cause
In
crates/victory-loader/src/prepare.rs(dir64_relocations), parsing theBASERELOCdata directory used unchecked arithmetic:end = start as usize + size as usizedid not saturate or clamp tobytes.len().at + block > endcould overflow on malformed block sizes.page + u32::from(e & 0xFFF)could overflow and panic in debug builds whenpage > u32::MAX - 0xFFF.Implementation Details
endto(start as usize).saturating_add(size as usize).min(bytes.len()).block < 8 || at + block > endwithat.checked_add(block).filter(|&next| block >= 8 && next <= end).page + u32::from(e & 0xFFF)withpage.checked_add(u32::from(e & 0xFFF)).Verification
dir64_relocations_clamps_oversized_directory_and_overflowing_pagesunit test incrates/victory-loader/src/prepare.rscovering oversizedu32::MAXdirectory sizes andu32::MAXpage base arithmetic.check(workspace build, clippy-D warnings, and tests) is green.Scope & Limitations
IMAGE_REL_BASED_DIR64relocation entries are unchanged; malformed overflowing entries are safely ignored.