Skip to content

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

Open
pedrofort wants to merge 2 commits into
Marvisak:mainfrom
pedrofort:fix-tls-callback-termination
Open

pedrofort wants to merge 2 commits into
Marvisak:mainfrom
pedrofort:fix-tls-callback-termination

Conversation

@pedrofort

Copy link
Copy Markdown

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.

muhammed-aksoy pushed a commit to muhammed-aksoy/VIctory that referenced this pull request Nov 24, 2026
edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
edsuuu referenced this pull request in edsuuu/VI-BR-PORT Nov 24, 2026
Its behaviour conflicts with other merged PRs (tests fail together).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jeremygold02

Copy link
Copy Markdown
Contributor

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

@etcetera-yt

Copy link
Copy Markdown
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.

@mercuryVM mercuryVM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested 8fc3a1b on Windows 11, RTX 5070, MSVC: cargo test -p victory-pe 13 passed, including the terminated, unterminated and over-limit TLS tests. cargo clippy -p victory-pe --all-targets is clean. victory inspect on a local title executable parses as before (same output and no error), so the stricter check doesn't reject a real image.

  • Requiring the null terminator inside the array's bytes matches what the Windows loader relies on: it walks until a null, so an unterminated array means it would read past the section. Refusing more than MAX_TLS_CALLBACKS (1024), instead of silently truncating, avoids running a partial set.
  • Nit: cargo fmt -p victory-pe --check reports diffs in the new tests (the hand-wrapped copy_from_slice( and ImageInfo::parse( calls). Running cargo fmt on the file would tidy them.

AI-assisted (Claude Code).

mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 24, 2026
…ck arrays

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
yourmomsbasement pushed a commit to yourmomsbasement/VIctory_Dev that referenced this pull request Nov 24, 2026
Merges Marvisak#188 Marvisak#213 Marvisak#214 Marvisak#219 Marvisak#221 Marvisak#311 Marvisak#324 Marvisak#363 Marvisak#406 Marvisak#454 Marvisak#529 Marvisak#560 Marvisak#708 Marvisak#937
Marvisak#941 Marvisak#963 Marvisak#1111 Marvisak#1159 Marvisak#1304 Marvisak#1306 onto main (ffe310e), each head unchanged,
no conflicts.

One change of mine: the long-format import descriptor code Marvisak#963 adds nests
`if size == 0` in an `if let`, which clippy::collapsible_if rejects under
-D warnings; it is now one `if let ... && size == 0` (clippy --fix, no
change of behaviour).

cargo clippy --workspace --all-targets --locked -- -D warnings, with and
without --all-features, is clean and cargo test --workspace --locked passes
(388 passed, 7 ignored; main has 342 passed, 6 ignored).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@pedrofort

Copy link
Copy Markdown
Author

Follow-up at c37793a: 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.

Copy link
Copy Markdown
Owner

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

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants