d3d12-pe: use synthetic PE32+ fixtures in portable image tests (D3D12-PE-PORTABLE-IMAGE-TESTS) #2878

Merged
matinsanei merged 4 commits from upstream-pr/2878 into main 2026-12-02 21:32:35 +00:00
matinsanei commented 2026-12-01 13:30:40 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by matinsanei on 2026-12-01T13:30:40Z.


Coordination item: D3D12-PE-PORTABLE-IMAGE-TESTS (claimed in https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7312616767).

Summary

leonida-pe is a portable crate with no Windows dependencies, yet cargo test -p leonida-pe failed 4 of 36 tests on Linux/non-Windows hosts because own_image() read std::env::current_exe() (which is an ELF/Mach-O binary, not PE32+).

Changes

  • d3d12/crates/leonida-pe/src/image.rs:
    • Added synthetic_pe_image() building a minimal valid PE32+ image with entry_rva = 0x1000.
    • Updated rva_to_file_offset_maps_entry_point, rva_to_file_offset_rejects_offsets_past_4_gib, rejects_garbage_without_panicking, and rejects_iat_outside_image to use synthetic PE32+ fixtures so they run on all platforms.
    • Gated own_image() and parses_own_test_binary (which inspects the host Windows test binary's .pdata and kernel32.dll imports) behind #[cfg(windows)].

Verification

  • Before change on Linux: cargo test --manifest-path d3d12/Cargo.toml -p leonida-pe -> 32 passed, 4 failed (Malformed("Unknown file magic")).
  • After change on Linux:
    • cargo test --manifest-path d3d12/Cargo.toml -p leonida-pe -> 35 passed, 0 failed.
    • cargo clippy --manifest-path d3d12/Cargo.toml -p leonida-pe --all-targets -- -D warnings -> clean.
    • cargo fmt --manifest-path d3d12/Cargo.toml -p leonida-pe -- --check -> clean.
    • python3 -I scripts/check_no_game_data.py d3d12/crates/leonida-pe/src/image.rs -> clean.
  • AI-assisted.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5586728434 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2878). Originally posted by [matinsanei](https://github.com/matinsanei) on 2026-12-01T13:30:40Z. --- Coordination item: `D3D12-PE-PORTABLE-IMAGE-TESTS` (claimed in https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7312616767). ### Summary `leonida-pe` is a portable crate with no Windows dependencies, yet `cargo test -p leonida-pe` failed 4 of 36 tests on Linux/non-Windows hosts because `own_image()` read `std::env::current_exe()` (which is an ELF/Mach-O binary, not PE32+). ### Changes - **`d3d12/crates/leonida-pe/src/image.rs`**: - Added `synthetic_pe_image()` building a minimal valid PE32+ image with `entry_rva = 0x1000`. - Updated `rva_to_file_offset_maps_entry_point`, `rva_to_file_offset_rejects_offsets_past_4_gib`, `rejects_garbage_without_panicking`, and `rejects_iat_outside_image` to use synthetic PE32+ fixtures so they run on all platforms. - Gated `own_image()` and `parses_own_test_binary` (which inspects the host Windows test binary's `.pdata` and `kernel32.dll` imports) behind `#[cfg(windows)]`. ### Verification - Before change on Linux: `cargo test --manifest-path d3d12/Cargo.toml -p leonida-pe` -> 32 passed, 4 failed (`Malformed("Unknown file magic")`). - After change on Linux: - `cargo test --manifest-path d3d12/Cargo.toml -p leonida-pe` -> 35 passed, 0 failed. - `cargo clippy --manifest-path d3d12/Cargo.toml -p leonida-pe --all-targets -- -D warnings` -> clean. - `cargo fmt --manifest-path d3d12/Cargo.toml -p leonida-pe -- --check` -> clean. - `python3 -I scripts/check_no_game_data.py d3d12/crates/leonida-pe/src/image.rs` -> clean. - AI-assisted.
copilot-pull-request-reviewer[bot] commented 2026-12-01 13:30:51 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-12-01T13:30:51Z.

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.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6132223814 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2878#pullrequestreview-6132223814). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-12-01T13:30:51Z. **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. An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. [Learn about Copilot code review billing](https://docs.github.com/en/copilot/concepts/agents/code-review#code-review-usage).
merzleckeier commented 2026-12-01 13:43:42 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-01T13:43:42Z.


Verified both the portable suite and the real Windows PE test at 52fcdeb81 + 9f27ba2e1, with Rust 1.98.1. On native Linux, cargo test --locked -p leonida-pe --lib on main gave 32 passes and four failures from parsing an ELF executable as PE. With the PR it gave 35 passes and zero failures. The Win64 MSVC-target binary under Wine 11.22 passed all 36 tests, explicitly including image::tests::parses_own_test_binary. The Linux arms used independent Cargo target directories.

AI-assisted with OpenAI Codex (GPT-6).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7313079331 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2878#issuecomment-7313079331). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-12-01T13:43:42Z. --- Verified both the portable suite and the real Windows PE test at `52fcdeb81` + `9f27ba2e1`, with Rust 1.98.1. On native Linux, `cargo test --locked -p leonida-pe --lib` on main gave 32 passes and four failures from parsing an ELF executable as PE. With the PR it gave 35 passes and zero failures. The Win64 MSVC-target binary under Wine 11.22 passed all 36 tests, explicitly including `image::tests::parses_own_test_binary`. The Linux arms used independent Cargo target directories. AI-assisted with OpenAI Codex (GPT-6).
KelboLive commented 2026-12-01 14:03:10 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-01T14:03:10Z.

Review: COMMENTED


Tests now build the image at test time from constants with explicit to_le_bytes at fixed offsets — no committed binary, no usize/size_of/repr(C), so endianness and padding cannot change the bytes. That fixes the current_exe()/ELF problem properly rather than papering over it, and cargo check --target x86_64-unknown-linux-gnu --all-targets compiles clean, so no dangling own_image reference is left in the non-Windows configuration. 36/36 here, fmt and clippy clean, check_no_game_data clean.

Parity with the old assertions holds where it matters: the RVA test still fails if the entry is outside the section (mutation), and the IAT-overflow test still requires the import walker to run — deleting every descriptor parse fails it. The new is_ok() positive control is load-bearing, which I checked rather than assumed: removing it lets the test go green on a fixture whose import name points outside the image.

Two small nits:

  1. The positive control only asserts is_ok(), so nothing proves the import was actually decoded — assert_eq!(info.imports[0].dll, "test.dll") is free here and would make the fixture's purpose visible.
  2. rejects_garbage_without_panicking now truncates to 0x100 where the old 0x200 also passes (I checked: the old value still passes), so the case quietly shifted from "raw data missing, headers intact" to "section table missing". Keeping 0x200 would have preserved exactly the old coverage.

One thing to record, not fix here: #[cfg(windows)] on parses_own_test_binary makes explicit something that was already Windows-only (it failed, not skipped, on Linux), but non-Windows now exercises no real-PE import/TLS/exception coverage. Fine for a portability change; a synthetic import + TLS fixture would close it if Linux CI ever runs this crate.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6132795603 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2878#pullrequestreview-6132795603). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-12-01T14:03:10Z. **Review:** COMMENTED --- Tests now build the image at test time from constants with explicit `to_le_bytes` at fixed offsets — no committed binary, no `usize`/`size_of`/`repr(C)`, so endianness and padding cannot change the bytes. That fixes the `current_exe()`/ELF problem properly rather than papering over it, and `cargo check --target x86_64-unknown-linux-gnu --all-targets` compiles clean, so no dangling `own_image` reference is left in the non-Windows configuration. 36/36 here, fmt and clippy clean, `check_no_game_data` clean. Parity with the old assertions holds where it matters: the RVA test still fails if the entry is outside the section (mutation), and the IAT-overflow test still requires the import walker to run — deleting every descriptor parse fails it. The new `is_ok()` positive control is load-bearing, which I checked rather than assumed: removing it lets the test go green on a fixture whose import name points outside the image. Two small nits: 1. The positive control only asserts `is_ok()`, so nothing proves the import was actually decoded — `assert_eq!(info.imports[0].dll, "test.dll")` is free here and would make the fixture's purpose visible. 2. `rejects_garbage_without_panicking` now truncates to **0x100** where the old **0x200** also passes (I checked: the old value still passes), so the case quietly shifted from "raw data missing, headers intact" to "section table missing". Keeping 0x200 would have preserved exactly the old coverage. One thing to record, not fix here: `#[cfg(windows)]` on `parses_own_test_binary` makes explicit something that was already Windows-only (it failed, not skipped, on Linux), but non-Windows now exercises **no** real-PE import/TLS/exception coverage. Fine for a portability change; a synthetic import + TLS fixture would close it if Linux CI ever runs this crate.
imShangLi commented 2026-12-01 15:34:15 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by imShangLi on 2026-12-01T15:34:15Z.


VERIFY-2878 — Linux, Rust 1.98.1 (the pinned toolchain), no GPU device, no game files

Verdict: PASS. The four image tests that could only run on Windows now run everywhere, and the Windows-only coverage is kept. I broke the code under test five ways; four of the five were caught, and the one that was not is a weak assertion that predates this pull request.

Head 58456fb4, base the current main 88a9f133, merge base ed867d7b, 1 commit, 1 file, +29/−10: d3d12/crates/leonida-pe/src/image.rs. The whole change is inside mod tests; no production code is touched.

1. What it changes

The tests used the test binary itself as the PE fixture:

fn own_image() -> Vec<u8> {
    std::fs::read(std::env::current_exe().unwrap()).unwrap()
}

which is an ELF on Linux and a PE only on Windows. The pull request keeps that for the one test that is genuinely about a real MSVC image (#[cfg(windows)] fn parses_own_test_binary) and gives the other four a hand-built PE32+ image:

fn synthetic_pe_image() -> Vec<u8> {
    let mut data = synthetic_image(&[]);
    let opt = 0x58;
    data[opt + 16..opt + 20].copy_from_slice(&0x1000u32.to_le_bytes());  // AddressOfEntryPoint
    data[opt + 112..opt + 120].fill(0);                                  // clear the export directory
    data
}

leonida-pe is one of the crates that builds on Linux, so this is measurable here.

2. Red and green, on Linux

tree cargo test -p leonida-pe
main 88a9f133 32 passed, 4 FAILED
this pull request 58456fb4 35 passed, 0 failed

The four failures on main are exactly the fixture-dependent ones, and they fail for the reason the pull request describes — the fixture is not a PE:

test image::tests::parses_own_test_binary ... FAILED
  panicked at crates/leonida-pe/src/image.rs:451:51
test image::tests::rva_to_file_offset_maps_entry_point ... FAILED
test image::tests::rva_to_file_offset_rejects_offsets_past_4_gib ... FAILED
test image::tests::rejects_iat_outside_image ... FAILED

So on main these four tests are red on every non-Windows machine — they are not skipped, they fail. This pull request turns them green everywhere.

3. The fixture is a correct PE32+ image

I checked the layout arithmetic field by field against synthetic_image (image.rs:533), which builds a 0x400-byte file:

field value offset
e_lfanew 0x40 d[0x3C..0x40]
PE\0\0 d[0x40..0x44]
machine / sections AMD64 / 1 d[0x44..0x48]
optional header size / magic 240 / 0x20B (PE32+) d[0x54..0x58], d[0x58..0x5A]
AddressOfEntryPoint 0x1000 d[opt+16..opt+20], set by synthetic_pe_image
SectionAlignment / FileAlignment 0x2000 / 0x200 d[opt+56..opt+64]
NumberOfRvaAndSizes 16 d[opt+108..opt+112]
section .edata RVA 0x1000, raw 0x200, raw size 0x200 d[opt+240..opt+264]

The file is 0x400 bytes and the section's raw data is 0x200..0x400, so RVA 0x1000 maps to file offset 0x200 — and that is exactly what the test's own arithmetic assumes (Name at RVA 0x1028 → file 0x228, FirstThunk at RVA 0x1034 → file 0x234). The import descriptor is at file 0x200, which is RVA 0x1000 ✓, and the PR writes "test.dll\0" at 0x228 ✓. The IMAGE_IMPORT_DESCRIPTOR field offsets it uses (+12 Name, +16 FirstThunk) are right. The export directory is cleared because the section has no real export table.

4. Breaking the code under test

This pull request touches only tests, so the question is whether the tests would notice the code they cover being wrong. I mutated the production code and ran the suite each time:

mutation caught by
M1 rva_to_file_offset returns the offset XOR 1 (wrong, but still inside the file) nothing — see §5
M2 the 4 GiB guard checked_add → wrapping_add rva_to_file_offset_rejects_offsets_past_4_gib
M3 the ordinary import's DLL name decoded as something else rejects_iat_outside_image
M4 the entry point read from the wrong optional-header offset rva_to_file_offset_maps_entry_point
M6 the section raw-data bounds check disabled rejects_garbage_without_panicking, rejects_section_extending_beyond_file

M2 and M6 are the two boundary guards the tests exist for, and both are caught. M3 and M4 show that the fixture is read the way the test intends.

5. The new assertion is what pins the import name

The pull request adds one assertion:

let info = ImageInfo::parse(&data).unwrap();
assert_eq!(info.imports[0].dll, "test.dll");

I removed that line and re-ran M3 (the import name decoded as "wrong.dll"): 35 passed, 0 failed — the mutation is no longer noticed. With the line in place, M3 is caught. So that one assertion is what makes the import-name decoding covered at all; the rest of the test only checks that parsing fails in one case.

6. One assertion that is weaker than it looks

rva_to_file_offset_maps_entry_point asserts only that the offset is inside the file:

let off = info.rva_to_file_offset(info.entry_rva).unwrap() as usize;
assert!(off < data.len());

M1 returns an offset that is one byte wrong and still inside the file, and the whole suite stays green. The correct answer is known now that the fixture is synthetic — RVA 0x1000 is the section at file offset 0x200 — so assert_eq!(off, 0x200) would pin the mapping. This weakness is in main as well (the same assertion over own_image()); the pull request does not introduce it, and I am not asking for a change, but the synthetic fixture makes the fix a one-liner.

7. What I did not check

  • Windows. Everything above is Linux (Fedora 45, x86_64) with the pinned toolchain (rustc 1.98.1). parses_own_test_binary is #[cfg(windows)] and did not run here, so the Windows-only path — parsing a real MSVC-linked PE32+ image and checking .pdata, the TLS directory and kernel32.dll — is unchanged by this pull request but also unverified by me.
  • Whether the synthetic image covers what the real one covered. The four portable tests now exercise a synthetic image with one section, no exports and two import descriptors; main's versions exercised the test binary, with its real section table, real exports and a real import table. The portable tests are narrower in what they see. The real-image coverage is kept by parses_own_test_binary, but it is the one test that cannot run off Windows.
  • The other crates in the workspace — leonida-gpu, leonida-hle and leonida-loader do not build on Linux for reasons that predate this pull request (upstream: "The crates are Windows-only today … Linux follows #2577"), so I ran leonida-pe on its own and not the workspace suite.
  • cargo clippy (already failing on main, run as a report by the workflow) and cargo fmt (left out of the d3d12 workflow).

AI-assisted: MiniMax M3.1 Flash.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7316138146 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2878#issuecomment-7316138146). Originally posted by [imShangLi](https://github.com/imShangLi) on 2026-12-01T15:34:15Z. --- ## VERIFY-2878 — Linux, Rust 1.98.1 (the pinned toolchain), no GPU device, no game files **Verdict: PASS.** The four image tests that could only run on Windows now run everywhere, and the Windows-only coverage is kept. I broke the code under test five ways; four of the five were caught, and the one that was not is a weak assertion that predates this pull request. Head `58456fb4`, base the current `main` `88a9f133`, merge base `ed867d7b`, 1 commit, 1 file, +29/−10: `d3d12/crates/leonida-pe/src/image.rs`. The whole change is inside `mod tests`; no production code is touched. ### 1. What it changes The tests used the test binary itself as the PE fixture: ```rust fn own_image() -> Vec<u8> { std::fs::read(std::env::current_exe().unwrap()).unwrap() } ``` which is an **ELF** on Linux and a PE only on Windows. The pull request keeps that for the one test that is genuinely about a real MSVC image (`#[cfg(windows)] fn parses_own_test_binary`) and gives the other four a hand-built PE32+ image: ```rust fn synthetic_pe_image() -> Vec<u8> { let mut data = synthetic_image(&[]); let opt = 0x58; data[opt + 16..opt + 20].copy_from_slice(&0x1000u32.to_le_bytes()); // AddressOfEntryPoint data[opt + 112..opt + 120].fill(0); // clear the export directory data } ``` `leonida-pe` is one of the crates that builds on Linux, so this is measurable here. ### 2. Red and green, on Linux | tree | `cargo test -p leonida-pe` | |---|---| | `main` `88a9f133` | **32 passed, 4 FAILED** | | this pull request `58456fb4` | **35 passed, 0 failed** | The four failures on `main` are exactly the fixture-dependent ones, and they fail for the reason the pull request describes — the fixture is not a PE: ``` test image::tests::parses_own_test_binary ... FAILED panicked at crates/leonida-pe/src/image.rs:451:51 test image::tests::rva_to_file_offset_maps_entry_point ... FAILED test image::tests::rva_to_file_offset_rejects_offsets_past_4_gib ... FAILED test image::tests::rejects_iat_outside_image ... FAILED ``` So on `main` these four tests are **red on every non-Windows machine** — they are not skipped, they fail. This pull request turns them green everywhere. ### 3. The fixture is a correct PE32+ image I checked the layout arithmetic field by field against `synthetic_image` (`image.rs:533`), which builds a 0x400-byte file: | field | value | offset | |---|---|---| | `e_lfanew` | 0x40 | `d[0x3C..0x40]` | | `PE\0\0` | | `d[0x40..0x44]` | | machine / sections | AMD64 / 1 | `d[0x44..0x48]` | | optional header size / magic | 240 / 0x20B (PE32+) | `d[0x54..0x58]`, `d[0x58..0x5A]` | | `AddressOfEntryPoint` | 0x1000 | `d[opt+16..opt+20]`, set by `synthetic_pe_image` | | `SectionAlignment` / `FileAlignment` | 0x2000 / 0x200 | `d[opt+56..opt+64]` | | `NumberOfRvaAndSizes` | 16 | `d[opt+108..opt+112]` | | section `.edata` | RVA 0x1000, raw 0x200, raw size 0x200 | `d[opt+240..opt+264]` | The file is 0x400 bytes and the section's raw data is 0x200..0x400, so RVA 0x1000 maps to file offset 0x200 — and that is exactly what the test's own arithmetic assumes (`Name` at RVA 0x1028 → file 0x228, `FirstThunk` at RVA 0x1034 → file 0x234). The import descriptor is at file 0x200, which is RVA 0x1000 ✓, and the PR writes "test.dll\0" at 0x228 ✓. The `IMAGE_IMPORT_DESCRIPTOR` field offsets it uses (`+12` Name, `+16` FirstThunk) are right. The export directory is cleared because the section has no real export table. ### 4. Breaking the code under test This pull request touches only tests, so the question is whether the tests would notice the code they cover being wrong. I mutated the production code and ran the suite each time: | mutation | caught by | |---|---| | M1 `rva_to_file_offset` returns the offset XOR 1 (wrong, but still inside the file) | **nothing — see §5** | | M2 the 4 GiB guard `checked_add` → `wrapping_add` | `rva_to_file_offset_rejects_offsets_past_4_gib` | | M3 the ordinary import's DLL name decoded as something else | `rejects_iat_outside_image` | | M4 the entry point read from the wrong optional-header offset | `rva_to_file_offset_maps_entry_point` | | M6 the section raw-data bounds check disabled | `rejects_garbage_without_panicking`, `rejects_section_extending_beyond_file` | M2 and M6 are the two boundary guards the tests exist for, and both are caught. M3 and M4 show that the fixture is read the way the test intends. ### 5. The new assertion is what pins the import name The pull request adds one assertion: ```rust let info = ImageInfo::parse(&data).unwrap(); assert_eq!(info.imports[0].dll, "test.dll"); ``` I removed that line and re-ran M3 (the import name decoded as "wrong.dll"): **35 passed, 0 failed** — the mutation is no longer noticed. With the line in place, M3 is caught. So that one assertion is what makes the import-name decoding covered at all; the rest of the test only checks that parsing fails in one case. ### 6. One assertion that is weaker than it looks `rva_to_file_offset_maps_entry_point` asserts only that the offset is inside the file: ```rust let off = info.rva_to_file_offset(info.entry_rva).unwrap() as usize; assert!(off < data.len()); ``` M1 returns an offset that is one byte wrong and still inside the file, and the whole suite stays green. The correct answer is known now that the fixture is synthetic — RVA 0x1000 is the section at file offset 0x200 — so `assert_eq!(off, 0x200)` would pin the mapping. This weakness is in `main` as well (the same assertion over `own_image()`); the pull request does not introduce it, and I am not asking for a change, but the synthetic fixture makes the fix a one-liner. ### 7. What I did not check - **Windows.** Everything above is Linux (Fedora 45, x86_64) with the pinned toolchain (`rustc 1.98.1`). `parses_own_test_binary` is `#[cfg(windows)]` and did not run here, so the Windows-only path — parsing a real MSVC-linked PE32+ image and checking `.pdata`, the TLS directory and `kernel32.dll` — is unchanged by this pull request but also unverified by me. - **Whether the synthetic image covers what the real one covered.** The four portable tests now exercise a synthetic image with one section, no exports and two import descriptors; `main`'s versions exercised the test binary, with its real section table, real exports and a real import table. The portable tests are narrower in what they see. The real-image coverage is kept by `parses_own_test_binary`, but it is the one test that cannot run off Windows. - **The other crates in the workspace** — `leonida-gpu`, `leonida-hle` and `leonida-loader` do not build on Linux for reasons that predate this pull request (upstream: "The crates are Windows-only today … Linux follows #2577"), so I ran `leonida-pe` on its own and not the workspace suite. - `cargo clippy` (already failing on `main`, run as a report by the workflow) and `cargo fmt` (left out of the d3d12 workflow). AI-assisted: MiniMax M3.1 Flash.
Neutron-0 commented 2026-12-01 16:20:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Neutron-0 on 2026-12-01T16:20:43Z.


Verified on Windows 11, Rust 1.98.1, no GPU and no game files.

cargo test -p leonida-pe --lib on the head 63b8ea9d3: 36 passed, 0 failed. On this Windows machine the same suite on the base e04721c7f also passes (36/36), which is expected: own_image() reads the host's PE32+ test binary, and on Windows that is a PE32+ image. The four failures in the report are the non-Windows case, which this machine cannot run, so that half of the claim is not measurable here.

What is measurable here, and it holds. The four tests no longer depend on the host binary at all: rva_to_file_offset_maps_entry_point, rva_to_file_offset_rejects_offsets_past_4_gib, rejects_garbage_without_panicking and rejects_iat_outside_image now build a synthetic PE32+ image and assert exact values (rva_to_file_offset of the entry point is 0x200, the import descriptor's DLL name is test.dll) rather than "the offset is somewhere in the buffer". The overflow guards the tests were written for - rva + 0x20 past 4 GiB, a FirstThunk of 0xFFFF_FFF8 - are still exercised, now against a fixture whose bytes are known.

Two notes, neither blocking.

  1. synthetic_pe_image() builds on synthetic_image(&[]), the helper the layout tests use, so the fixture is the same shape the crate's own layout constants describe; that is the right base. The import directory is written into the section at RVA 0x1000 (file offset 0x200), whose size is 40 bytes for two descriptors, while the fixture's section holds only the one descriptor that is written - the second descriptor's bytes are whatever the section already holds (zeroes). ImageInfo::parse stops at the zeroed descriptor, so the count is right, but a reader that walked both descriptors would read the zeroes as a second entry with OriginalFirstThunk = 0. Writing the second descriptor's terminator explicitly would make the fixture's intent ("two descriptors") true rather than implied.
  2. #[cfg(windows)] on own_image() and parses_own_test_binary is the right call, and the test count on Windows stays at 36. On Linux the count drops by one (the gated test) while the four rewritten tests stay, which is what the report describes.

The change is the right shape: the crate is portable, and a test that reads the host's executable is a test that only runs where the host happens to be the format under test.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7317447944 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2878#issuecomment-7317447944). Originally posted by [Neutron-0](https://github.com/Neutron-0) on 2026-12-01T16:20:43Z. --- Verified on Windows 11, Rust 1.98.1, no GPU and no game files. **`cargo test -p leonida-pe --lib` on the head `63b8ea9d3`: 36 passed, 0 failed.** On this Windows machine the same suite on the base `e04721c7f` also passes (36/36), which is expected: `own_image()` reads the host's PE32+ test binary, and on Windows that is a PE32+ image. The four failures in the report are the non-Windows case, which this machine cannot run, so that half of the claim is not measurable here. **What is measurable here, and it holds.** The four tests no longer depend on the host binary at all: `rva_to_file_offset_maps_entry_point`, `rva_to_file_offset_rejects_offsets_past_4_gib`, `rejects_garbage_without_panicking` and `rejects_iat_outside_image` now build a synthetic PE32+ image and assert exact values (`rva_to_file_offset` of the entry point is `0x200`, the import descriptor's DLL name is `test.dll`) rather than "the offset is somewhere in the buffer". The overflow guards the tests were written for - `rva + 0x20` past 4 GiB, a `FirstThunk` of `0xFFFF_FFF8` - are still exercised, now against a fixture whose bytes are known. **Two notes, neither blocking.** 1. `synthetic_pe_image()` builds on `synthetic_image(&[])`, the helper the layout tests use, so the fixture is the same shape the crate's own layout constants describe; that is the right base. The import directory is written into the section at RVA `0x1000` (file offset `0x200`), whose size is 40 bytes for two descriptors, while the fixture's section holds only the one descriptor that is written - the second descriptor's bytes are whatever the section already holds (zeroes). `ImageInfo::parse` stops at the zeroed descriptor, so the count is right, but a reader that walked both descriptors would read the zeroes as a second entry with `OriginalFirstThunk = 0`. Writing the second descriptor's terminator explicitly would make the fixture's intent ("two descriptors") true rather than implied. 2. `#[cfg(windows)]` on `own_image()` and `parses_own_test_binary` is the right call, and the test count on Windows stays at 36. On Linux the count drops by one (the gated test) while the four rewritten tests stay, which is what the report describes. The change is the right shape: the crate is portable, and a test that reads the host's executable is a test that only runs where the host happens to be the format under test.
MoonEyes commented 2026-12-02 12:29:53 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T12:29:53Z.


This pull request touches the render path, so it needs an in-game run before it can be merged: unit tests and CI do not catch rendering regressions (a device loss after an earlier merge is why this gate exists).

Could you, or anyone with a working setup, post a run report on the current head merged onto current main:

  • the head SHA and the main SHA it was merged onto;
  • GPU, driver and OS;
  • at least 300 s in the world after loading;
  • device lost / crashes (count), and rendered fps (median) if you have them;
  • the same run on main alone for comparison, if you can.

Please do not attach logs or screenshots that show game content. If a run on this exact head is already posted, a link to it in a reply is enough.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7345428959 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2878#issuecomment-7345428959). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T12:29:53Z. --- This pull request touches the render path, so it needs an in-game run before it can be merged: unit tests and CI do not catch rendering regressions (a device loss after an earlier merge is why this gate exists). Could you, or anyone with a working setup, post a run report on the **current head** merged onto current `main`: - the head SHA and the `main` SHA it was merged onto; - GPU, driver and OS; - at least 300 s in the world after loading; - device lost / crashes (count), and rendered fps (median) if you have them; - the same run on `main` alone for comparison, if you can. Please do not attach logs or screenshots that show game content. If a run on this exact head is already posted, a link to it in a reply is enough. AI-assisted (Claude Code).
MoonEyes commented 2026-12-02 18:14:36 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T18:14:36Z.


Verified on Linux: this is exactly the case the PR fixes. On current main, four leonida-pe tests fail off Windows; with the head merged, all pass.

head      63b8ea9d3
base      origin/main 45dc41f95, merge base ed867d7b2 (517 commits behind), merged locally without conflict (56e40a6fd)
toolchain Rust 1.98.1 (pinned), x86_64-unknown-linux-gnu, no GPU, no game files
Tree cargo test -p leonida-pe --locked (from d3d12/)
main 45dc41f95 (red) FAILED. 32 passed; 4 failed: parses_own_test_binary, rva_to_file_offset_maps_entry_point, rejects_iat_outside_image, rva_to_file_offset_rejects_offsets_past_4_gib (each reads the test binary itself, which is ELF here)
main + this head (green) ok. 35 passed; 0 failed (parses_own_test_binary is now #[cfg(windows)], so 35 rather than 36)

Read in the diff: test-only, in d3d12/crates/leonida-pe/src/image.rs. synthetic_pe_image() builds on the existing synthetic_image(&[]), sets the entry RVA to the one section, and clears the export directory. rva_to_file_offset_maps_entry_point now asserts the exact offset (0x200) instead of off < data.len(), which is stronger. rejects_iat_outside_image builds its own import descriptor and first checks that the image parses with test.dll before it corrupts FirstThunk, so the error it then expects comes from the corruption, not from a broken fixture. The real-binary check stays on Windows. No production code changes.

CI: the two red checks on this head (check, linux-python-and-viewer, run 2026-12-01 16:1x) fail in Python tests this PR does not touch (the test_f.T.test_a fixture in the TLS-callback tests and the fuzz Reference errors). That is main at the old merge base. A run after merging current main should clear them.

The render-path gate requested on this PR does not apply to a test-only diff, as far as I can see: nothing outside #[cfg(test)] changes.

Verdict: ready once CI is rerun on a head that includes current main.

AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.


Generated by Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7354200339 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2878#issuecomment-7354200339). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T18:14:36Z. --- **Verified on Linux: this is exactly the case the PR fixes. On current `main`, four `leonida-pe` tests fail off Windows; with the head merged, all pass.** ``` head 63b8ea9d3 base origin/main 45dc41f95, merge base ed867d7b2 (517 commits behind), merged locally without conflict (56e40a6fd) toolchain Rust 1.98.1 (pinned), x86_64-unknown-linux-gnu, no GPU, no game files ``` | Tree | `cargo test -p leonida-pe --locked` (from `d3d12/`) | |---|---| | `main` 45dc41f95 (red) | **FAILED. 32 passed; 4 failed**: `parses_own_test_binary`, `rva_to_file_offset_maps_entry_point`, `rejects_iat_outside_image`, `rva_to_file_offset_rejects_offsets_past_4_gib` (each reads the test binary itself, which is ELF here) | | `main` + this head (green) | ok. 35 passed; 0 failed (`parses_own_test_binary` is now `#[cfg(windows)]`, so 35 rather than 36) | **Read in the diff:** test-only, in `d3d12/crates/leonida-pe/src/image.rs`. `synthetic_pe_image()` builds on the existing `synthetic_image(&[])`, sets the entry RVA to the one section, and clears the export directory. `rva_to_file_offset_maps_entry_point` now asserts the exact offset (`0x200`) instead of `off < data.len()`, which is stronger. `rejects_iat_outside_image` builds its own import descriptor and first checks that the image parses with `test.dll` before it corrupts `FirstThunk`, so the error it then expects comes from the corruption, not from a broken fixture. The real-binary check stays on Windows. No production code changes. **CI:** the two red checks on this head (`check`, `linux-python-and-viewer`, run 2026-12-01 16:1x) fail in Python tests this PR does not touch (the `test_f.T.test_a` fixture in the TLS-callback tests and the fuzz `Reference` errors). That is `main` at the old merge base. A run after merging current `main` should clear them. The render-path gate requested on this PR does not apply to a test-only diff, as far as I can see: nothing outside `#[cfg(test)]` changes. **Verdict: ready** once CI is rerun on a head that includes current `main`. AI-assisted verification: Claude Opus (Claude Code), separate agent per batch. --- _Generated by [Claude Code](https://claude.ai/code)_
MoonEyes commented 2026-12-02 19:28:07 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T19:28:07Z.


Re-verified on the current head (Linux): the four leonida-pe tests still fail on main and pass with the head. The PR's code is unchanged; the new commit only merges main.

head      ab38b0136
base      origin/main b41763227 (= merge base, 0 behind); merged --no-ff without conflict
since     63b8ea9d3: one commit, ab38b0136 "Merge branch 'main' ... into fix/leonida-pe-portable-tests";
          the PR's own diff (d3d12/crates/leonida-pe/src/image.rs +30/-11) is byte-for-byte the one verified before
toolchain Rust 1.98.1 (pinned), x86_64-unknown-linux-gnu, no GPU, no game files
Tree cargo test -p leonida-pe --locked (from d3d12/)
main b41763227 (red) FAILED. 32 passed; 4 failed: parses_own_test_binary, rva_to_file_offset_maps_entry_point, rejects_iat_outside_image, rva_to_file_offset_rejects_offsets_past_4_gib
main + head (green) ok. 35 passed; 0 failed
  • python -I scripts/check_no_game_data.py d3d12/crates/leonida-pe/src/image.rs: exit 0.
  • Full standalone suite (CI selection into python -I scripts/run_standalone_tests.py -j 8): 660 files, 1 failed (tests/test_run_game_wine.py). Plain main gives the same result, and the failure comes from the local environment, not this PR.

Earlier report: no defects. The CI failures it noted came from the old merge base and are gone: on ab38b0136, check, linux-python-and-viewer, no-game-data and semantic-tests pass.

CI, one red job: d3d12 (windows-latest) failed in leonida-lua, not in this PR's crate. tests::a_scan_without_a_size_reaches_the_end_of_the_image panicked at crates\leonida-lua\src\tests.rs:587 (["tail 1 0"] vs ["tail 1 1"]). That flaky test is already in main; the cause, an unaligned fake image base, is explained on #3179. The job stopped there, so parses_own_test_binary in leonida-pe, which runs only on Windows, did not run on this head. A rerun of that job should confirm it.

The diff is test-only (#[cfg(test)]), so as far as I can see the render-path gate does not apply.

Verdict: ready once d3d12 (windows-latest) is rerun and passes leonida-pe.

AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.


Generated by Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7356222388 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2878#issuecomment-7356222388). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T19:28:07Z. --- **Re-verified on the current head (Linux): the four `leonida-pe` tests still fail on `main` and pass with the head. The PR's code is unchanged; the new commit only merges `main`.** ``` head ab38b0136 base origin/main b41763227 (= merge base, 0 behind); merged --no-ff without conflict since 63b8ea9d3: one commit, ab38b0136 "Merge branch 'main' ... into fix/leonida-pe-portable-tests"; the PR's own diff (d3d12/crates/leonida-pe/src/image.rs +30/-11) is byte-for-byte the one verified before toolchain Rust 1.98.1 (pinned), x86_64-unknown-linux-gnu, no GPU, no game files ``` | Tree | `cargo test -p leonida-pe --locked` (from `d3d12/`) | |---|---| | `main` b41763227 (red) | **FAILED. 32 passed; 4 failed**: `parses_own_test_binary`, `rva_to_file_offset_maps_entry_point`, `rejects_iat_outside_image`, `rva_to_file_offset_rejects_offsets_past_4_gib` | | `main` + head (green) | ok. 35 passed; 0 failed | - `python -I scripts/check_no_game_data.py d3d12/crates/leonida-pe/src/image.rs`: exit 0. - Full standalone suite (CI selection into `python -I scripts/run_standalone_tests.py -j 8`): 660 files, 1 failed (`tests/test_run_game_wine.py`). Plain `main` gives the same result, and the failure comes from the local environment, not this PR. **Earlier report:** no defects. The CI failures it noted came from the old merge base and are gone: on `ab38b0136`, `check`, `linux-python-and-viewer`, `no-game-data` and `semantic-tests` pass. **CI, one red job:** `d3d12 (windows-latest)` failed in `leonida-lua`, not in this PR's crate. `tests::a_scan_without_a_size_reaches_the_end_of_the_image` panicked at `crates\leonida-lua\src\tests.rs:587` (`["tail 1 0"]` vs `["tail 1 1"]`). That flaky test is already in `main`; the cause, an unaligned fake image base, is explained on #3179. The job stopped there, so `parses_own_test_binary` in `leonida-pe`, which runs only on Windows, did not run on this head. A rerun of that job should confirm it. The diff is test-only (`#[cfg(test)]`), so as far as I can see the render-path gate does not apply. **Verdict: ready** once `d3d12 (windows-latest)` is rerun and passes `leonida-pe`. AI-assisted verification: Claude Opus (Claude Code), separate agent per batch. --- _Generated by [Claude Code](https://claude.ai/code)_
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
ProjectLeonida/mandy!2878
No description provided.