WIP: fix(builder): a Windows program's image ends at its FileAlignment, so the nightly attaches its pack #2583

Closed
HumanBean wants to merge 1 commit from HumanBean/Longshot:fix/pe-attach-file-alignment into main
Owner

Summary

Nightly fd68f82c's Windows job (run 54507) linked longshot-builder.exe and then failed at dev release attach:

/tmp/longshot-builder.exe: it carries something past its image already: attach to a program that carries no pack

lld pads a PE file to its FileAlignment (512 bytes) after the COFF string table. The builder's .exe is 26,725,888 bytes, but its headers, sections, symbols and string table end at 26,725,593. The 295 zero bytes after them are that padding, so the program looked like it already carried something. image_end now rounds a PE's end up to its FileAlignment. A FileAlignment that is not a power of two (or a hand-made test file's 0) leaves the end as it was.

This is the first nightly with the pack appended after linking (#2557), so no earlier Windows nightly hit it. Linux was not affected: an ELF's section headers end the file.

Read builder/crates/build-driver/src/sources.rs: image_end and its new test.

Testing

Tested: Linux (CachyOS).

  • The real program: built longshot-builder.exe here as CI does (scripts/longshot_builder.py build --target windows --profile dist, llvm-mingw 20261104). It came out the same size as the nightly's, 26,725,888 bytes, with 295 bytes past what main's image_end counts. A Linux builder from this branch attached a pack to it (dev release attach) and wrote the file at 26,725,888 + pack + 64 bytes. On main, the same step is the nightly's refusal above.
  • Game-free test: a_pe_program_s_padding_after_its_symbols_is_its_image models lld's layout (a section, two COFF symbols, a string table, the padding to 0x200). It fails on main (image_end gives 0x42A, so attach refuses) and passes here. This PR's CI runs it; per this PC's rule, no tests ran here. cargo clippy -p build-driver --all-targets is clean.

Still to test: the next nightly's Windows job attaches and publishes.

Measurements

Nothing to measure: a check on a file's layout.

Risks

Low. A file cut short inside the last 511 bytes of padding now reads as having no pack. It also has no trailer, so it is still a damaged download, which the release's SHA256SUMS catches. Revert to undo.

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). (this PR's CI runs it)
  • 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.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • 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.

🤖 Generated with Claude Code

https://claude.ai/code/session_017vw8e1RP1VgcWpgA7Kq6ec

## Summary Nightly fd68f82c's Windows job ([run 54507](https://git.magicbean.dev/MagicBeanDev/Longshot/actions/runs/54507/jobs/5/attempt/1)) linked `longshot-builder.exe` and then failed at `dev release attach`: ``` /tmp/longshot-builder.exe: it carries something past its image already: attach to a program that carries no pack ``` lld pads a PE file to its FileAlignment (512 bytes) after the COFF string table. The builder's `.exe` is 26,725,888 bytes, but its headers, sections, symbols and string table end at 26,725,593. The 295 zero bytes after them are that padding, so the program looked like it already carried something. `image_end` now rounds a PE's end up to its FileAlignment. A FileAlignment that is not a power of two (or a hand-made test file's 0) leaves the end as it was. This is the first nightly with the pack appended after linking ([#2557](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2557)), so no earlier Windows nightly hit it. Linux was not affected: an ELF's section headers end the file. Read `builder/crates/build-driver/src/sources.rs`: `image_end` and its new test. ## Testing **Tested:** Linux (CachyOS). - **The real program:** built `longshot-builder.exe` here as CI does (`scripts/longshot_builder.py build --target windows --profile dist`, llvm-mingw 20261104). It came out the same size as the nightly's, 26,725,888 bytes, with 295 bytes past what main's `image_end` counts. A Linux builder from this branch attached a pack to it (`dev release attach`) and wrote the file at 26,725,888 + pack + 64 bytes. On main, the same step is the nightly's refusal above. - **Game-free test:** `a_pe_program_s_padding_after_its_symbols_is_its_image` models lld's layout (a section, two COFF symbols, a string table, the padding to 0x200). It fails on main (`image_end` gives 0x42A, so attach refuses) and passes here. This PR's CI runs it; per this PC's rule, no tests ran here. `cargo clippy -p build-driver --all-targets` is clean. **Still to test:** the next nightly's Windows job attaches and publishes. ## Measurements Nothing to measure: a check on a file's layout. ## Risks Low. A file cut short inside the last 511 bytes of padding now reads as having no pack. It also has no trailer, so it is still a damaged download, which the release's SHA256SUMS catches. Revert to undo. ## 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. - [ ] `mise run test` passes (any failure that also fails on `main` is named). (this PR's CI runs it) - [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] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] 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. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_017vw8e1RP1VgcWpgA7Kq6ec
fix(builder): a Windows program's image ends at its FileAlignment, so attaching the pack accepts lld's padding
Some checks failed
PR description / Title and description (pull_request_target) Successful in 11s
CI / What the change needs (pull_request) Successful in 11s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Failing after 1s
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Failing after 1s
CI / Game-free checks (run_all.py, part 2/2) (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 / Website build and checks (pull_request) Failing after 0s
CI / Third-party parts and guide screenshots (pull_request) Successful in 14s
b7e1cd0ed7
The nightly's Windows job (run 54507) linked longshot-builder.exe and then refused to attach its pack: lld pads the
file to its FileAlignment (512) after the COFF string table, 295 zero bytes past what image_end counted, so the
program looked as if it carried something already. image_end rounds a PE's end up to its FileAlignment; a test
models lld's layout (symbols, string table, padding).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017vw8e1RP1VgcWpgA7Kq6ec
Member

Possibly related, for context:

  • PR #2581 fix(builder): a Windows longshot-builder no longer takes its file's zero padding for a download cut short — Open overlapping fix to PE image-end padding in the same source file
Possibly related, for context: - PR #2581 fix(builder): a Windows longshot-builder no longer takes its file's zero padding for a download cut short — Open overlapping fix to PE image-end padding in the same source file
Author
Owner

Closing as a duplicate of #2581, which fixes the same FileAlignment padding and is better: it counts the padding only when every byte of it is zero and in the file, so a download cut short inside the padding is still refused, and it updates builder.md. Measured here too: this PC's dist longshot-builder.exe has 295 zero bytes after its string table, the nightly's (run 54507) is the same size.

Closing as a duplicate of https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2581, which fixes the same FileAlignment padding and is better: it counts the padding only when every byte of it is zero and in the file, so a download cut short inside the padding is still refused, and it updates builder.md. Measured here too: this PC's dist longshot-builder.exe has 295 zero bytes after its string table, the nightly's (run 54507) is the same size.
HumanBean closed this pull request 2026-11-26 00:56:36 +00:00
Some checks failed
PR description / Title and description (pull_request_target) Successful in 11s
CI / What the change needs (pull_request) Successful in 11s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Failing after 1s
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Failing after 1s
CI / Game-free checks (run_all.py, part 2/2) (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 / Website build and checks (pull_request) Failing after 0s
CI / Third-party parts and guide screenshots (pull_request) Successful in 14s

Pull request closed

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!2583
No description provided.