fix(builder): a Windows longshot-builder no longer takes its file's zero padding for a download cut short #2581

Merged
HumanBean merged 2 commits from pmwork-personal/Longshot:fix/builder-pe-padding into main 2026-11-26 02:29:34 +00:00
Member

Summary

Since #2557 (fd68f82c), a longshot-builder with bytes past its program image and no pack trailer refuses to run: it
takes them for a download that did not end. On Windows, every developer build of the builder refuses itself. To see it
on main on Windows: build the builder (cargo build --release -p longshot-builder), then dev.py pack with it
(LONGSHOT_BUILD). It stops at once with "What this longshot-builder carries could not be unpacked (the program's file
is cut short or damaged: a download that did not end). Download longshot-builder again." The same happens in
build-driver's own test a_program_with_no_trailer_carries_nothing, which reads the test program's own file.
erlo68 saw the same symptom (#2241's description).

The cause: for a PE, image_end counts the headers, the sections, and the COFF symbols and their string table. It does
not count the zeros that llvm-mingw's lld writes after the string table, up to the PE's FileAlignment (512). A
developer's build keeps its COFF symbols, so its file ends with 255 to 462 such zero bytes (measured below). The same
can apply to the shipped Windows builder: the dist profile strips the debug information but keeps the symbols, and a
dist build on this PC has 226 zero bytes after its string table. With main's image_end, dev release attach
refuses such a program ("it carries something past its image already"). No nightly has run since #2557, so the
release's Windows step has not run this yet.

This change: image_end also counts those zeros, up to the next FileAlignment boundary. It does this only when every
byte there is zero and in the file. A byte that is not zero, or padding that the file does not have whole, is still
past the image, so a download cut short is still refused. ELF programs do not change.

Read first: image_end in builder/crates/build-driver/src/sources.rs (the PE branch) and its new tests at the end
of the file. docs/dev/reference/builder.md gets one sentence on it.

Testing

Tested: Windows 11, llvm-mingw, Rust 1.99.1:

  • cargo test --locked -p build-driver (its own cargo target folder, through the job queue): on the test commit
    (fc2c2e90, main's code plus the new tests), 120 passed and 10 failed. Three of the failures are this bug:
    a_pe_program_s_zero_padding_to_its_file_alignment_carries_nothing (image_end 0x431, not 0x600),
    a_pack_is_attached_to_a_padded_pe_program ("it carries something past its image already") and
    a_program_with_no_trailer_carries_nothing (128734258, not the file's 128734720 bytes). On the fix (c55adf5a), 123
    passed and 7 failed: all five PE tests pass. The other 7 fail on Windows with and without this change and read no
    file this changes: channel::tests::profile_says_the_folder_and_the_known_keys,
    modhook::tests::a_context_resolves_the_profile_and_its_game (a path with ../../../target against its canonical
    form), folder::tests::a_romfs_folder_is_the_builder_s_only_when_it_made_it,
    read::tests::a_dump_s_build_takes_no_romfs_folder_of_the_player_s,
    modhook::tests::the_dev_mod_folders_are_joined_by_the_os_separator, perf::tests::one_sender_at_a_time (os error
    183, the file already exists) and sources::tests::each_unpack_marks_its_folders_used. CI runs these tests on Linux.
  • A broken fix: with the zero check taken out, a_pe_program_s_padding_with_a_byte_that_is_not_zero_is_refused fails
    and the other PE tests pass.
  • cargo clippy --locked -p build-driver --all-targets -- -D warnings: no warnings. cargo fmt --check: clean.
  • In real use: a release-profile builder with main's image_end stops dev.py pack with the message above. The
    builder from this branch makes the pack over the shared base (the game's code lifted and compiled, the game folder
    put together). The game does not run this code (it is the builder's check of its own file), so there was no game
    run.
  • tests/run_all.py --strict --changed: 4 passed (test_ship_state_list, byte_compile_tracked, test_mise_build,
    test_no_release_lookup). The whole suite (tests/run_all.py --strict, Windows): 791 passed, 19 failed, 48 skipped.
    None of the 19 reads a file this changes (--changed). 15 failed the same way on main (68ab0bc7) on this PC in
    an earlier run: test_auto_handheld, test_builder_channel, test_coverage_run, test_dev_ab, test_dev_build,
    test_dev_migrate, test_float_add_subgroup, test_game_menu_mouse_buttons, test_input_movie, test_job_queue,
    test_oot_menu_mouse, test_pads_after_menu, test_parity_gates, test_run_all_mingw and test_sampler_admission (its "id
    concurrent" case, also alone). test_lifter, test_fsr3fi_hud_layer and test_fsr3fi_hudless_colour need llvm-mc and
    glslang, which are not on this PC's PATH (--strict fails them). test_invalidate_vcore timed out with 16 checks
    at once and passes alone.

Still to test:

  • The first nightly after this merges, Windows builder step: dev release attach appends the pack to the dist
    program and longshot_builder.py check passes (by hand, watching the run).

Measurements

Verdict: a Windows developer build of longshot-builder runs again; nothing to measure for speed (one check of the
builder's own file at its start).

Setup: Windows 11, llvm-mingw's lld, Rust 1.99.1; the bytes after the COFF string table in each program, read from its
headers.

Before: main @ fd68f82c After: this PR @ c55adf5a
cargo test -p build-driver, the five PE tests 3 fail 5 pass
dev.py pack with the branch's own builder stops: "cut short or damaged" the pack
Test program (build-driver's tests): zeros after the string table 462, refused the image's (the test passes)
release builder: zeros after the string table 255, refused 326, the image's
dist builder: zeros after the string table not measured 226, the image's

Risks

What could break: a PE whose file ends with up to 511 zero bytes after its image now counts them as its image. Those
bytes can only be zero, so no carried pack (which starts with its magic) is taken into the image, and a release
program with a pack reads its pack as before (a_pack_is_attached_to_a_padded_pe_program checks both a padded program
and one whose string table ends the file). A revert brings the refusal back. Players notice nothing: a released
builder that ran before runs the same.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A fix: a game-free test that fails on main and passes here.
  • A check under tests/ that reads changed source is updated, not weakened. (test_no_release_lookup and
    test_ship_state_list read sources.rs; both pass unchanged, so neither needs an update.)
  • Docs updated.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

Co-Authored-By: Claude Opus 5.5 [email protected]

🤖 Generated with Claude Code

## Summary Since #2557 (`fd68f82c`), a `longshot-builder` with bytes past its program image and no pack trailer refuses to run: it takes them for a download that did not end. On Windows, every developer build of the builder refuses itself. To see it on `main` on Windows: build the builder (`cargo build --release -p longshot-builder`), then `dev.py pack` with it (`LONGSHOT_BUILD`). It stops at once with "What this longshot-builder carries could not be unpacked (the program's file is cut short or damaged: a download that did not end). Download longshot-builder again." The same happens in `build-driver`'s own test `a_program_with_no_trailer_carries_nothing`, which reads the test program's own file. erlo68 saw the same symptom (#2241's description). The cause: for a PE, `image_end` counts the headers, the sections, and the COFF symbols and their string table. It does not count the zeros that llvm-mingw's lld writes after the string table, up to the PE's FileAlignment (512). A developer's build keeps its COFF symbols, so its file ends with 255 to 462 such zero bytes (measured below). The same can apply to the shipped Windows builder: the `dist` profile strips the debug information but keeps the symbols, and a `dist` build on this PC has 226 zero bytes after its string table. With `main`'s `image_end`, `dev release attach` refuses such a program ("it carries something past its image already"). No nightly has run since #2557, so the release's Windows step has not run this yet. This change: `image_end` also counts those zeros, up to the next FileAlignment boundary. It does this only when every byte there is zero and in the file. A byte that is not zero, or padding that the file does not have whole, is still past the image, so a download cut short is still refused. ELF programs do not change. Read first: `image_end` in `builder/crates/build-driver/src/sources.rs` (the PE branch) and its new tests at the end of the file. `docs/dev/reference/builder.md` gets one sentence on it. ## Testing **Tested:** Windows 11, llvm-mingw, Rust 1.99.1: - `cargo test --locked -p build-driver` (its own cargo target folder, through the job queue): on the test commit (`fc2c2e90`, `main`'s code plus the new tests), 120 passed and 10 failed. Three of the failures are this bug: `a_pe_program_s_zero_padding_to_its_file_alignment_carries_nothing` (`image_end` 0x431, not 0x600), `a_pack_is_attached_to_a_padded_pe_program` ("it carries something past its image already") and `a_program_with_no_trailer_carries_nothing` (128734258, not the file's 128734720 bytes). On the fix (`c55adf5a`), 123 passed and 7 failed: all five PE tests pass. The other 7 fail on Windows with and without this change and read no file this changes: `channel::tests::profile_says_the_folder_and_the_known_keys`, `modhook::tests::a_context_resolves_the_profile_and_its_game` (a path with `../../../target` against its canonical form), `folder::tests::a_romfs_folder_is_the_builder_s_only_when_it_made_it`, `read::tests::a_dump_s_build_takes_no_romfs_folder_of_the_player_s`, `modhook::tests::the_dev_mod_folders_are_joined_by_the_os_separator`, `perf::tests::one_sender_at_a_time` (os error 183, the file already exists) and `sources::tests::each_unpack_marks_its_folders_used`. CI runs these tests on Linux. - A broken fix: with the zero check taken out, `a_pe_program_s_padding_with_a_byte_that_is_not_zero_is_refused` fails and the other PE tests pass. - `cargo clippy --locked -p build-driver --all-targets -- -D warnings`: no warnings. `cargo fmt --check`: clean. - In real use: a release-profile builder with `main`'s `image_end` stops `dev.py pack` with the message above. The builder from this branch makes the pack over the shared base (the game's code lifted and compiled, the game folder put together). The game does not run this code (it is the builder's check of its own file), so there was no game run. - `tests/run_all.py --strict --changed`: 4 passed (test_ship_state_list, byte_compile_tracked, test_mise_build, test_no_release_lookup). The whole suite (`tests/run_all.py --strict`, Windows): 791 passed, 19 failed, 48 skipped. None of the 19 reads a file this changes (`--changed`). 15 failed the same way on `main` (`68ab0bc7`) on this PC in an earlier run: test_auto_handheld, test_builder_channel, test_coverage_run, test_dev_ab, test_dev_build, test_dev_migrate, test_float_add_subgroup, test_game_menu_mouse_buttons, test_input_movie, test_job_queue, test_oot_menu_mouse, test_pads_after_menu, test_parity_gates, test_run_all_mingw and test_sampler_admission (its "id concurrent" case, also alone). test_lifter, test_fsr3fi_hud_layer and test_fsr3fi_hudless_colour need `llvm-mc` and `glslang`, which are not on this PC's PATH (`--strict` fails them). test_invalidate_vcore timed out with 16 checks at once and passes alone. **Still to test:** - The first nightly after this merges, Windows builder step: `dev release attach` appends the pack to the `dist` program and `longshot_builder.py check` passes (by hand, watching the run). ## Measurements **Verdict:** a Windows developer build of `longshot-builder` runs again; nothing to measure for speed (one check of the builder's own file at its start). Setup: Windows 11, llvm-mingw's lld, Rust 1.99.1; the bytes after the COFF string table in each program, read from its headers. | | Before: main @ `fd68f82c` | After: this PR @ `c55adf5a` | |---|---|---| | `cargo test -p build-driver`, the five PE tests | 3 fail | 5 pass | | `dev.py pack` with the branch's own builder | stops: "cut short or damaged" | the pack | | Test program (`build-driver`'s tests): zeros after the string table | 462, refused | the image's (the test passes) | | `release` builder: zeros after the string table | 255, refused | 326, the image's | | `dist` builder: zeros after the string table | not measured | 226, the image's | ## Risks What could break: a PE whose file ends with up to 511 zero bytes after its image now counts them as its image. Those bytes can only be zero, so no carried pack (which starts with its magic) is taken into the image, and a release program with a pack reads its pack as before (`a_pack_is_attached_to_a_padded_pe_program` checks both a padded program and one whose string table ends the file). A revert brings the refusal back. Players notice nothing: a released builder that ran before runs the same. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [x] `mise run test` passes (any failure that also fails on `main` is named). - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A fix: a game-free test that fails on `main` and passes here. - [x] A check under `tests/` that reads changed source is updated, not weakened. (test_no_release_lookup and test_ship_state_list read `sources.rs`; both pass unchanged, so neither needs an update.) - [x] Docs updated. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. Co-Authored-By: Claude Opus 5.5 <[email protected]> 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A tiny PE as llvm-mingw's lld links a program that keeps its COFF symbols (a developer's build): the symbols and their
string table after the last section, then zeros up to the PE's FileAlignment. It carries nothing, `attach` takes it,
and padding with a byte that is not zero is still refused. Fails on main: image_end stops at the string table, so the
zeros are taken for bytes past the image (a download cut short).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fix(build-driver): a Windows developer build's zero padding to FileAlignment is part of its image
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
Website / Website preview, built by CI (pull_request_target) Has been skipped
Website / Website preview, upload (pull_request_target) Has been skipped
CI / What the change needs (pull_request) Successful in 7s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Failing after 1s
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Failing after 1s
CI / Website build and checks (pull_request) Failing after 1s
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Failing after 1s
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Failing after 1s
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Failing after 1s
CI / Third-party parts and guide screenshots (pull_request) Successful in 11s
PR description / Title and description (pull_request_target) Successful in 19s
c55adf5ac9
Since #2557, a program with bytes past its image and no trailer is refused as a download cut short. For a PE,
image_end counted the sections and the COFF symbols and string table, but not the zeros that llvm-mingw's lld pads the
file with after the string table, up to the PE's FileAlignment, in a program that keeps its COFF symbols (a
developer's build; a dist build here too). So every Windows developer build of longshot-builder refused itself, and
`dev.py pack` stopped with "the program's file is cut short or damaged". image_end now takes those zeros as the
image's: only zeros, and only bytes the file has.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Member

Tested in game: Windows 11, llvm-mingw, Rust 1.99.1: longshot-builder built from this branch (release profile) built the game as a pack over the shared base (dev.py pack: the game's code lifted and compiled, the game folder put together). With main's image_end the same builder stops at once with 'cut short or damaged'. The game does not run this code (the builder's check of its own file), so the game was not started.

Tested in game: Windows 11, llvm-mingw, Rust 1.99.1: longshot-builder built from this branch (release profile) built the game as a pack over the shared base (dev.py pack: the game's code lifted and compiled, the game folder put together). With main's image_end the same builder stops at once with 'cut short or damaged'. The game does not run this code (the builder's check of its own file), so the game was not started.
HumanBean force-pushed fix/builder-pe-padding from c55adf5ac9
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
Website / Website preview, built by CI (pull_request_target) Has been skipped
Website / Website preview, upload (pull_request_target) Has been skipped
CI / What the change needs (pull_request) Successful in 7s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Failing after 1s
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Failing after 1s
CI / Website build and checks (pull_request) Failing after 1s
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Failing after 1s
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Failing after 1s
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Failing after 1s
CI / Third-party parts and guide screenshots (pull_request) Successful in 11s
PR description / Title and description (pull_request_target) Successful in 19s
to 34f90a1b40
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
Website / Website preview, built by CI (pull_request_target) Has been skipped
Website / Website preview, upload (pull_request_target) Has been skipped
PR description / Title and description (pull_request_target) Successful in 8s
CI / What the change needs (pull_request) Successful in 18s
CI / Third-party parts and guide screenshots (pull_request) Successful in 30s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Successful in 2m35s
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Successful in 2m3s
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Successful in 3m24s
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Failing after 5m40s
CI / Website build and checks (pull_request) Successful in 2m48s
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Successful in 37m50s
2026-11-26 02:01:40 +00:00
Compare
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
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
MagicBeanDev/Longshot!2581
No description provided.