fix(pe): detect incomplete TLS callback arrays #324

Open
github-bot wants to merge 2 commits from github-bot/gh-324 into main AGit
Owner

@⁠pedrofort on GitHub · 2026-11-24 02:18 UTC · original
pedrofort:fix-tls-callback-termination → main · +169 −1 · 1 files · 2 commits · open

<head></head>

Problem

parse_tls() silently accepts callback arrays that reach the end of the available section data without a null terminator, or contain more than MAX_TLS_CALLBACKS entries.

In both cases, ImageInfo::parse() can return a partial callback list without reporting an error.

Proposed fix

  • Report an explicit malformed-image error for unterminated callback arrays.

  • Reject arrays exceeding the existing 1,024-callback limit instead of silently truncating them.

  • Preserve valid empty arrays, null callback pointers and arrays containing exactly 1,024 callbacks followed by a terminator.

One compatibility detail for review: whether callback arrays terminated by implicit zero-filled virtual memory should also be accepted.

Verification

Tested on Apple M5, macOS arm64, Rust 1.98.1, against main d2a4bae.

Check | Before | After -- | -- | -- Synthetic TLS tests | 4 passed, 2 failed | 6 passed, 0 failed Portable PE unit tests | — | 9 passed, 0 failed Clippy | — | Clean Asset policy | — | 151 files OK

The four existing Windows-specific own-binary tests were excluded from the portable PE test run.

All new fixtures are generated in memory. No game data was used.

AI-assisted implementation and test preparation (ChatGPT). Commands executed and results verified locally.

**@⁠pedrofort** on GitHub · 2026-11-24 02:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/324) `pedrofort:fix-tls-callback-termination` → `main` · +169 −1 · 1 files · 2 commits · open <head></head><h2 style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-style: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>Problem</span></h2><p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><code><span>parse_tls()</span></code><span><span class="Apple-converted-space"> </span>silently accepts callback arrays that reach the end of the available section data without a null terminator, or contain more than<span class="Apple-converted-space"> </span></span><code><span>MAX_TLS_CALLBACKS</span></code><span><span class="Apple-converted-space"> </span>entries.</span></p><p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>In both cases,<span class="Apple-converted-space"> </span></span><code><span>ImageInfo::parse()</span></code><span><span class="Apple-converted-space"> </span>can return a partial callback list without reporting an error.</span></p><h2 style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-style: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>Proposed fix</span></h2><ul style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><li><p><span>Report an explicit malformed-image error for unterminated callback arrays.</span></p></li><li><p><span>Reject arrays exceeding the existing 1,024-callback limit instead of silently truncating them.</span></p></li><li><p><span>Preserve valid empty arrays, null callback pointers and arrays containing exactly 1,024 callbacks followed by a terminator.</span></p></li></ul><p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>One compatibility detail for review: whether callback arrays terminated by implicit zero-filled virtual memory should also be accepted.</span></p><h2 style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-style: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>Verification</span></h2><p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>Tested on Apple M5, macOS arm64, Rust 1.98.1, against main<span class="Apple-converted-space"> </span></span><code><span>d2a4bae</span></code><span>.</span></p> Check | Before | After -- | -- | -- Synthetic TLS tests | 4 passed, 2 failed | 6 passed, 0 failed Portable PE unit tests | — | 9 passed, 0 failed Clippy | — | Clean Asset policy | — | 151 files OK <p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>The four existing Windows-specific own-binary tests were excluded from the portable PE test run.</span></p><p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>All new fixtures are generated in memory. No game data was used.</span></p><p style="caret-color: rgb(255, 255, 255); color: rgb(255, 255, 255); font-size: medium; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span>AI-assisted implementation and test preparation (ChatGPT). Commands executed and results verified locally.</span></p>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:59:20 +00:00
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-24 04:20 UTC · original

Tested PR #324 at head 8fc3a1bb2f37c6220c8f9a397ff5d1a99f6e34a7 (state at test time: OPEN). Pre-comment refresh: state OPEN, head unchanged at 8fc3a1bb2f37c6220c8f9a397ff5d1a99f6e34a7.

  • cargo test --locked -p victory-pe --lib tls_probe_ — passed (ok. 6 passed; 0 failed; 0 ignored; 0 measured; 7 filtered out; finished in 0.00s ); cases: image::tests::tls_probe_accepts_terminated_callbacks, image::tests::tls_probe_accepts_null_callback_pointer, image::tests::tls_probe_accepts_empty_callback_list, image::tests::tls_probe_accepts_exact_callback_limit, and 2 more.

Behavior covered: Checks TLS callback arrays accept terminated, empty and null forms while rejecting unterminated and over-limit arrays.
Code: crates/victory-pe/src/image.rs

**@⁠jeremygold02** on GitHub · 2026-11-24 04:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/324#issuecomment-7121926244) Tested PR #324 at head `8fc3a1bb2f37c6220c8f9a397ff5d1a99f6e34a7` (state at test time: OPEN). Pre-comment refresh: state OPEN, head unchanged at `8fc3a1bb2f37c6220c8f9a397ff5d1a99f6e34a7`. - `cargo test --locked -p victory-pe --lib tls_probe_` — passed (ok. 6 passed; 0 failed; 0 ignored; 0 measured; 7 filtered out; finished in 0.00s ); cases: image::tests::tls_probe_accepts_terminated_callbacks, image::tests::tls_probe_accepts_null_callback_pointer, image::tests::tls_probe_accepts_empty_callback_list, image::tests::tls_probe_accepts_exact_callback_limit, and 2 more. Behavior covered: Checks TLS callback arrays accept terminated, empty and null forms while rejecting unterminated and over-limit arrays. Code: [crates/victory-pe/src/image.rs](https://github.com/Marvisak/VIctory/blob/8fc3a1bb2f37c6220c8f9a397ff5d1a99f6e34a7/crates/victory-pe/src/image.rs)
Author
Owner

@⁠etcetera-yt on GitHub · 2026-11-24 05:36 UTC · original

main + #287 + #311:          tls_callbacks_are_capped ... ok, tls_callback_array_stops_at_the_end_of_the_section ... ok
main + #287 + #311 + #324:   both FAILED
  crates\victory-pe\tests\synthetic_image.rs:616:36  Malformed("TLS callback count exceeds limit")
  crates\victory-pe\tests\synthetic_image.rs:534:36  Malformed("unterminated TLS callback array")

The synthetic-image tests expect ImageInfo::parse to succeed on an image whose TLS callback array is past the
cap or runs to the end of its section (capping or stopping there). #324 rejects both images as malformed. The two
PRs disagree on the intended behaviour; one of them needs to change, and the maintainer should pick which.

Merged with plain git merge, no text conflict. Windows 10 19045, Rust 1.98.1, cargo test -p victory-pe tls_callback.

AI use: Claude Code, Claude Opus 5.5.

**@⁠etcetera-yt** on GitHub · 2026-11-24 05:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/324#issuecomment-7123106707) ``` main + #287 + #311: tls_callbacks_are_capped ... ok, tls_callback_array_stops_at_the_end_of_the_section ... ok main + #287 + #311 + #324: both FAILED crates\victory-pe\tests\synthetic_image.rs:616:36 Malformed("TLS callback count exceeds limit") crates\victory-pe\tests\synthetic_image.rs:534:36 Malformed("unterminated TLS callback array") ``` The synthetic-image tests expect `ImageInfo::parse` to succeed on an image whose TLS callback array is past the cap or runs to the end of its section (capping or stopping there). #324 rejects both images as malformed. The two PRs disagree on the intended behaviour; one of them needs to change, and the maintainer should pick which. Merged with plain `git merge`, no text conflict. Windows 10 19045, Rust 1.98.1, `cargo test -p victory-pe tls_callback`. AI use: Claude Code, Claude Opus 5.5.
Author
Owner

@⁠pedrofort on GitHub · 2026-11-24 20:14 UTC · original

Follow-up at c37793a059: fixed a reproduced synthetic compatibility defect involving TLS terminators in zero-filled virtual memory. All 9 focused TLS tests and portable PE regressions passed on Apple M5. Formatting and asset policy passed. Platform-specific own-PE tests were excluded on macOS; the IAT test failure was independently reproduced on the original commit. Whether this fixes the reported title-loading regression remains unverified. Independent retesting appreciated. AI-assisted with ChatGPT.

**@⁠pedrofort** on GitHub · 2026-11-24 20:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/324#issuecomment-7143238364) Follow-up at c37793a059e393026c5dbf9cfc4a8e2cc23090c2: fixed a reproduced synthetic compatibility defect involving TLS terminators in zero-filled virtual memory. All 9 focused TLS tests and portable PE regressions passed on Apple M5. Formatting and asset policy passed. Platform-specific own-PE tests were excluded on macOS; the IAT test failure was independently reproduced on the original commit. Whether this fixes the reported title-loading regression remains unverified. Independent retesting appreciated. AI-assisted with ChatGPT.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:31 UTC · original

Automated triage for the maintainers.

Proposed close: adds load failures for cases that do not occur. This makes parse_tls (crates/victory-pe/src/image.rs) reject an image whose TLS callback array is unterminated within the section's raw data, or has more than 1,024 callbacks (main already caps the walk at MAX_TLS_CALLBACKS). The Windows loader rejects neither case, so this is stricter than Windows: such an image would now fail to load. No real image is shown to have the problem, the title loads with today's behaviour, and a reviewer reports it conflicts with the expectations of the other open TLS PRs (#287, #311). A version that logs a warning instead of failing the parse would be a different proposal.

CI: check passing.

This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the triage: proposed close label.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/324#issuecomment-7148597311) <!-- victory-triage v1 head=c37793a059e393026c5dbf9cfc4a8e2cc23090c2 verdict=proposed-close at=2026-11-25T00:19:54Z --> Automated triage for the maintainers. **Proposed close: adds load failures for cases that do not occur.** This makes `parse_tls` (`crates/victory-pe/src/image.rs`) reject an image whose TLS callback array is unterminated within the section's raw data, or has more than 1,024 callbacks (main already caps the walk at `MAX_TLS_CALLBACKS`). The Windows loader rejects neither case, so this is stricter than Windows: such an image would now fail to load. No real image is shown to have the problem, the title loads with today's behaviour, and a reviewer reports it conflicts with the expectations of the other open TLS PRs (#287, #311). A version that logs a warning instead of failing the parse would be a different proposal. CI: `check` passing. This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the `triage: proposed close` label. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/324/head:github-bot/gh-324'
git switch 'github-bot/gh-324'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-324'
git switch 'github-bot/gh-324'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-324'
git switch 'github-bot/gh-324'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-324'
git switch 'main'
git merge --squash 'github-bot/gh-324'
git switch 'main'
git merge --ff-only 'github-bot/gh-324'
git switch 'main'
git merge 'github-bot/gh-324'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!324
No description provided.