TLS: clamp carrier template size before rounding to prevent u64/u32 overflow #1393

Merged
b3IKK merged 1 commit from upstream-pr/1403 into main 2026-12-02 17:38:08 +00:00
b3IKK commented 2026-11-24 15:38:53 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-24T15:38:53Z.


carrier_template_size_for computed (n + 15) & !15 before clamping, overflowing u64 when total_len > u64::MAX - 15 (and its upper bound u32::MAX - 0x10000 was not 16-byte aligned). build_carrier_dll_with only clamped at the lower bound (template_size.max(16)), so large template_size values overflowed u32 in OFF_TEMPLATE + template_size, DATA_RVA + data_vsize + 0xFFF, and va(OFF_TEMPLATE + template_size).

This defines MAX_CARRIER_TEMPLATE = (u32::MAX - 0x10000) & !15 and clamps to [16, MAX_CARRIER_TEMPLATE] in both functions.

What is in it

  • crates/xcl/src/tls.rs: clamp to [16, MAX_CARRIER_TEMPLATE] in carrier_template_size_for and build_carrier_dll_with; add unit test carrier_size_and_build_clamp_without_overflow (verified panicking on u64 addition overflow before the fix).

Tested

  • hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1)
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 752 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 no wave64 — gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware)
  • cargo test -p xcl --lib tls::tests: 5 passed, 0 failed, 1 ignored (carrier_size_and_build_clamp_without_overflow panicked before the fix)

Regression run

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1226 (PresentX 1226)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15341 MB

PR:

xcl-smoke v1
commit: ce99e53ac3ed43c7e74d445f949ecf856ade445b
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1640 (PresentX 1640)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14598 MB

Not tested

  • AMD GPUs and native wave64 hardware
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Gemini 4 Neon: audited tls.rs, wrote the fix and unit test, ran the test suite and scripts/smoke.ps1 regression runs, and drafted this PR description.
<!-- greyfinch-sync:ivall/xcl:issue:5475346667 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1403). Originally posted by [b3IKK](https://github.com/b3IKK) on 2026-11-24T15:38:53Z. --- `carrier_template_size_for` computed `(n + 15) & !15` before clamping, overflowing `u64` when `total_len > u64::MAX - 15` (and its upper bound `u32::MAX - 0x10000` was not 16-byte aligned). `build_carrier_dll_with` only clamped at the lower bound (`template_size.max(16)`), so large `template_size` values overflowed `u32` in `OFF_TEMPLATE + template_size`, `DATA_RVA + data_vsize + 0xFFF`, and `va(OFF_TEMPLATE + template_size)`. This defines `MAX_CARRIER_TEMPLATE = (u32::MAX - 0x10000) & !15` and clamps to `[16, MAX_CARRIER_TEMPLATE]` in both functions. **What is in it** - `crates/xcl/src/tls.rs`: clamp to `[16, MAX_CARRIER_TEMPLATE]` in `carrier_template_size_for` and `build_carrier_dll_with`; add unit test `carrier_size_and_build_clamp_without_overflow` (verified panicking on `u64` addition overflow before the fix). **Tested** - hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (`stable-x86_64-pc-windows-msvc`), DXC 1.9.2609.5, debug (`scripts/test.ps1`) and release (`scripts/smoke.ps1`) - `.\scripts\test.ps1` (`cargo build --workspace` + `cargo test --workspace -- --test-threads=4`): 752 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 `no wave64` — `gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware`) - `cargo test -p xcl --lib tls::tests`: 5 passed, 0 failed, 1 ignored (`carrier_size_and_build_clamp_without_overflow` panicked before the fix) **Regression run** main: ``` xcl-smoke v1 commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3 gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1226 (PresentX 1226) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15341 MB ``` PR: ``` xcl-smoke v1 commit: ce99e53ac3ed43c7e74d445f949ecf856ade445b gpu: NVIDIA GeForce RTX 5080 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1640 (PresentX 1640) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14598 MB ``` **Not tested** - AMD GPUs and native wave64 hardware - other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine **AI use** - OpenCode, Gemini 4 Neon: audited `tls.rs`, wrote the fix and unit test, ran the test suite and `scripts/smoke.ps1` regression runs, and drafted this PR description.
futurepro62 commented 2026-11-24 16:07:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T15:54:55Z.


Full-suite run, since this PR has no test report yet. Tested exact head ce99e53 (on its base 930e8b4).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 752 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: carrier_size_and_build_clamp_without_overflow.
  • Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 752 passed, 0 failed, 41 ignored, no skips.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:ivall/xcl:comment:7136823847 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/1403#issuecomment-7136823847). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-24T15:54:55Z. --- Full-suite run, since this PR has no test report yet. Tested exact head `ce99e53` (on its base `930e8b4`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4`: **752 passed, 0 failed, 41 ignored**. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. - The new tests ran and passed: `carrier_size_and_build_clamp_without_overflow`. - Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, `XCL_ADAPTER=radeon`), `cargo test --workspace -- --test-threads=4`: **752 passed, 0 failed, 41 ignored**, no skips. **Not tested** - a release build, a game (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
DavidM1911 commented 2026-11-24 17:06:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T17:01:48Z.


Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored.

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7138576263 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1403#issuecomment-7138576263). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T17:01:48Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~21 ignored. Thanks!
S1m0ne1997 commented 2026-11-25 15:08:03 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by S1m0ne1997 on 2026-11-25T14:55:21Z.


Test report for ce99e53ac3ed43c7e74d445f949ecf856ade445b (this PR's head), for #1607.

Tested

  • NVIDIA GeForce RTX 4090 24 GB (driver 621.40), AMD Ryzen 9 9950X3D, 47 GB RAM, Windows 11 Home 10.0.26300, rustc 1.100.0 (0ef1bc386 2026-11-09) x86_64-pc-windows-msvc, debug.
  • cargo build --workspace, then cargo test --workspace -- --test-threads=4 at the head: 752 passed, 0 failed, 41 ignored.
  • SKIPPED (2): gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu_wave32_program_in_wave64_hardware (no wave64).

Regression run (retail title, scripts/smoke.ps1 -Seconds 60, release; main built from the commit in its block, this PR from its head with no changes to crates/, both run with the scripts/smoke.ps1 of main, which hashes the name of the game folder)

main:

xcl-smoke v1
commit: 06c9f5505f63f10c5ec49ef932d75b2c28177324
gpu: NVIDIA GeForce RTX 4090
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1599 (PresentX 1599)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16384 MB

this PR:

xcl-smoke v1
commit: ce99e53ac3ed43c7e74d445f949ecf856ade445b
gpu: NVIDIA GeForce RTX 4090
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1617 (PresentX 1617)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17886 MB

Not tested

  • AMD, other NVIDIA cards and drivers, Linux. I did not review the diff; this report is the build, the suite and the regression run only.

AI use: Claude Code with Claude Opus 5.5 ran the build, the suite and the regression run and wrote this report at my request.

<!-- greyfinch-sync:ivall/xcl:comment:7166024843 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1403#issuecomment-7166024843). Originally posted by [S1m0ne1997](https://github.com/S1m0ne1997) on 2026-11-25T14:55:21Z. --- Test report for `ce99e53ac3ed43c7e74d445f949ecf856ade445b` (this PR's head), for #1607. **Tested** - NVIDIA GeForce RTX 4090 24 GB (driver 621.40), AMD Ryzen 9 9950X3D, 47 GB RAM, Windows 11 Home 10.0.26300, `rustc 1.100.0 (0ef1bc386 2026-11-09)` `x86_64-pc-windows-msvc`, debug. - `cargo build --workspace`, then `cargo test --workspace -- --test-threads=4` at the head: **752 passed, 0 failed, 41 ignored**. - SKIPPED (2): `gpu_geometry_wave32_prefix_count_over_a_mask` (no wave64), `gpu_wave32_program_in_wave64_hardware` (no wave64). **Regression run** (retail title, `scripts/smoke.ps1 -Seconds 60`, release; `main` built from the commit in its block, this PR from its head with no changes to `crates/`, both run with the `scripts/smoke.ps1` of `main`, which hashes the name of the game folder) main: ``` xcl-smoke v1 commit: 06c9f5505f63f10c5ec49ef932d75b2c28177324 gpu: NVIDIA GeForce RTX 4090 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1599 (PresentX 1599) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 16384 MB ``` this PR: ``` xcl-smoke v1 commit: ce99e53ac3ed43c7e74d445f949ecf856ade445b gpu: NVIDIA GeForce RTX 4090 title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1617 (PresentX 1617) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 17886 MB ``` **Not tested** - AMD, other NVIDIA cards and drivers, Linux. I did not review the diff; this report is the build, the suite and the regression run only. *AI use: Claude Code with Claude Opus 5.5 ran the build, the suite and the regression run and wrote this report at my request.*
github-actions[bot] commented 2026-11-29 20:42:25 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-29T20:42:25Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7262293348 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1403#issuecomment-7262293348). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-29T20:42:25Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
BBareth commented 2026-11-30 13:24:33 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by BBareth on 2026-11-30T13:24:33Z.


merge-check claim
head: ce99e53ac3

<!-- greyfinch-sync:ivall/xcl:comment:7279802299 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1403#issuecomment-7279802299). Originally posted by [BBareth](https://github.com/BBareth) on 2026-11-30T13:24:33Z. --- merge-check claim head: ce99e53ac3ed43c7e74d445f949ecf856ade445b
BBareth commented 2026-11-30 13:36:28 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by BBareth on 2026-11-30T13:36:28Z.


merge-check
base: 9dfbe3ea66
head: ce99e53ac3
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2886 passed, 1 failed, 51 ignored; failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, which fails on the base alone too (base: 2885 passed, 1 failed, 51 ignored, 28 SKIPPED lines). 28 SKIPPED lines, as on the base. The new test tls::tests::carrier_size_and_build_clamp_without_overflow passed, as did the existing tls tests.
review: no blocking finding; one file, every hunk read. carrier_template_size_for clamped after rounding: n + 15 overflowed for a length near u64::MAX (a panic in debug builds), and the old cap u32::MAX - 0x10000 is not a multiple of 16, so the largest result was not 16-aligned. The length is now clamped to (u32::MAX - 0x10000) & !15 first and then rounded, and build_carrier_dll_with clamps its argument to the same limit, so OFF_TEMPLATE + template_size and the image size stay inside u32. The test builds the largest carrier and parses it back. Sizes below the cap give the same result as before.
performance: none.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB, driver 621.24 (32.0.16.2124); i7-12700K; Windows 11 26200. Claude Code, Claude Fable 5.2 read the diff, ran the build and the suite and wrote this check.

<!-- greyfinch-sync:ivall/xcl:comment:7280088647 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1403#issuecomment-7280088647). Originally posted by [BBareth](https://github.com/BBareth) on 2026-11-30T13:36:28Z. --- merge-check base: 9dfbe3ea6653a9c76ef3ea0d66187a4b5407483b head: ce99e53ac3ed43c7e74d445f949ecf856ade445b merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2886 passed, 1 failed, 51 ignored; failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, which fails on the base alone too (base: 2885 passed, 1 failed, 51 ignored, 28 SKIPPED lines). 28 SKIPPED lines, as on the base. The new test `tls::tests::carrier_size_and_build_clamp_without_overflow` passed, as did the existing tls tests. review: no blocking finding; one file, every hunk read. `carrier_template_size_for` clamped after rounding: `n + 15` overflowed for a length near `u64::MAX` (a panic in debug builds), and the old cap `u32::MAX - 0x10000` is not a multiple of 16, so the largest result was not 16-aligned. The length is now clamped to `(u32::MAX - 0x10000) & !15` first and then rounded, and `build_carrier_dll_with` clamps its argument to the same limit, so `OFF_TEMPLATE + template_size` and the image size stay inside u32. The test builds the largest carrier and parses it back. Sizes below the cap give the same result as before. performance: none. verdict: safe to merge hardware / tool and model: RTX 5070 Ti 16 GB, driver 621.24 (32.0.16.2124); i7-12700K; Windows 11 26200. Claude Code, Claude Fable 5.2 read the diff, ran the build and the suite and wrote this check.
tiagonleal commented 2026-11-30 13:46:44 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by tiagonleal on 2026-11-30T13:46:44Z.


merge-check
base: 9dfbe3ea66
head: ce99e53ac3
merge: clean
build: cargo build --workspace -> ok (also cargo build --release -p xcl)
tests: cargo test --workspace --no-fail-fast -j 8 -- --test-threads=4 -> 2886 passed, 1 failed, 51 ignored; SKIPPED: 24 lines, the same as on the base; failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, which fails the same way on the base alone (2885 passed, 1 failed, 51 ignored; #3513 fixes it). The new test tls::tests::carrier_size_and_build_clamp_without_overflow ran and passed. With carrier_template_size_for put back to the two lines on main, it fails with "attempt to add with overflow" at tls.rs:80; file restored after.
review: one file, whole diff read, arithmetic checked at the edges. MAX_CARRIER_TEMPLATE is (0xFFFFFFFF - 0x10000) & !15 = 0xFFFEFFF0 (tls.rs:75). carrier_template_size_for (tls.rs:78-80): 0 gives 16, 16 gives 16, 17 gives 32, exact multiples are unchanged (0x1000 gives 0x1000). The cap is itself a multiple of 16, so after the clamp n + 15 is at most 0xFFFEFFFF and the result at most the cap, with no u64 or u32 overflow for any input up to u64::MAX. Below the cap the results are the same as on main; above it main returned 0xFFFEFFFF (not 16-aligned) and now 0xFFFEFFF0. build_carrier_dll_with (tls.rs:89): at the cap, OFF_TEMPLATE + template_size is 0xFFFF00F0 and DATA_RVA + data_vsize + 0xFFF is 0xFFFF40EF, both inside u32, and va() (tls.rs:164) adds in u32 before widening, also inside. It does not round its argument up to 16 (as on main), so a direct caller passing an unaligned size still gets that size. On main the only production caller (tls.rs:626) already passed at most 0xFFFEFFFF, which does not overflow the build arithmetic, so the u32 case was reachable only through a direct call, and the u64 case needed total_len > u64::MAX - 15. Outside the diff and not fixed here: total_len (pe.rs:140) adds size_of_zero_fill to template_len with a plain +, which can overflow first on a malformed TLS directory. Sizes over the cap are still cut silently rather than refused, as before. Overlap: #1431 rewrites both carrier_template_size_for and build_carrier_dll_with, so the second to land needs a rebase.
performance: scripts/smoke.ps1, 60 s of a retail title, release, after one warm-up run of the base: 1676 frames and 17943 MB peak commit against 1659 frames and 17322 MB on the base (warm-up: 1689, 17197 MB). No device removal, no crash. The title's TLS size is far below the cap, so its carrier is the same as on main; I read the commit difference as run-to-run spread (last of five runs in a row) but did not rerun to confirm it.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB (617.42, wave32), Ryzen 7 9800X3D, 32 GB, Windows 11 26300, rustc 1.100.0 / Claude Code (Claude Opus 5.5 ran the build, suite, tests and smoke, reviewed the diff against the merged source and wrote this)

  • Tiago
<!-- greyfinch-sync:ivall/xcl:comment:7280342950 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1403#issuecomment-7280342950). Originally posted by [tiagonleal](https://github.com/tiagonleal) on 2026-11-30T13:46:44Z. --- merge-check base: 9dfbe3ea6653a9c76ef3ea0d66187a4b5407483b head: ce99e53ac3ed43c7e74d445f949ecf856ade445b merge: clean build: cargo build --workspace -> ok (also `cargo build --release -p xcl`) tests: cargo test --workspace --no-fail-fast -j 8 -- --test-threads=4 -> 2886 passed, 1 failed, 51 ignored; SKIPPED: 24 lines, the same as on the base; failing: `gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16`, which fails the same way on the base alone (2885 passed, 1 failed, 51 ignored; #3513 fixes it). The new test `tls::tests::carrier_size_and_build_clamp_without_overflow` ran and passed. With `carrier_template_size_for` put back to the two lines on main, it fails with "attempt to add with overflow" at `tls.rs:80`; file restored after. review: one file, whole diff read, arithmetic checked at the edges. `MAX_CARRIER_TEMPLATE` is `(0xFFFFFFFF - 0x10000) & !15` = 0xFFFEFFF0 (`tls.rs:75`). `carrier_template_size_for` (`tls.rs:78-80`): 0 gives 16, 16 gives 16, 17 gives 32, exact multiples are unchanged (0x1000 gives 0x1000). The cap is itself a multiple of 16, so after the clamp `n + 15` is at most 0xFFFEFFFF and the result at most the cap, with no u64 or u32 overflow for any input up to `u64::MAX`. Below the cap the results are the same as on main; above it main returned 0xFFFEFFFF (not 16-aligned) and now 0xFFFEFFF0. `build_carrier_dll_with` (`tls.rs:89`): at the cap, `OFF_TEMPLATE + template_size` is 0xFFFF00F0 and `DATA_RVA + data_vsize + 0xFFF` is 0xFFFF40EF, both inside u32, and `va()` (`tls.rs:164`) adds in u32 before widening, also inside. It does not round its argument up to 16 (as on main), so a direct caller passing an unaligned size still gets that size. On main the only production caller (`tls.rs:626`) already passed at most 0xFFFEFFFF, which does not overflow the build arithmetic, so the u32 case was reachable only through a direct call, and the u64 case needed `total_len > u64::MAX - 15`. Outside the diff and not fixed here: `total_len` (`pe.rs:140`) adds `size_of_zero_fill` to `template_len` with a plain `+`, which can overflow first on a malformed TLS directory. Sizes over the cap are still cut silently rather than refused, as before. Overlap: #1431 rewrites both `carrier_template_size_for` and `build_carrier_dll_with`, so the second to land needs a rebase. performance: `scripts/smoke.ps1`, 60 s of a retail title, release, after one warm-up run of the base: 1676 frames and 17943 MB peak commit against 1659 frames and 17322 MB on the base (warm-up: 1689, 17197 MB). No device removal, no crash. The title's TLS size is far below the cap, so its carrier is the same as on main; I read the commit difference as run-to-run spread (last of five runs in a row) but did not rerun to confirm it. verdict: safe to merge hardware / tool and model: RTX 5070 Ti 16 GB (617.42, wave32), Ryzen 7 9800X3D, 32 GB, Windows 11 26300, rustc 1.100.0 / Claude Code (Claude Opus 5.5 ran the build, suite, tests and smoke, reviewed the diff against the merged source and wrote this) - Tiago
Foniass commented 2026-12-01 05:38:38 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:38:38Z.


Triage (#1607) – head ce99e53

#196 contains the same clamp in tls.rs::carrier_template_size_for / build_carrier_dll_with (total_len.clamp(16, MAX_CARRIER_TEMPLATE)) as part of a 500-line TLS alignment and locking rework, and #1431 caps the size through a new carrier_template_size_aligned helper. This PR is the overflow fix on its own, with a test.
No problems found in the diff: the new cap is 16-aligned (the old min(u32::MAX - 0x10000) was not) and DATA_RVA + OFF_TEMPLATE + cap + 0xFFF stays below u32::MAX.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7301986016 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1403#issuecomment-7301986016). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T05:38:38Z. --- **Triage (#1607)** – head ce99e53 #196 contains the same clamp in tls.rs::carrier_template_size_for / build_carrier_dll_with (total_len.clamp(16, MAX_CARRIER_TEMPLATE)) as part of a 500-line TLS alignment and locking rework, and #1431 caps the size through a new carrier_template_size_aligned helper. This PR is the overflow fix on its own, with a test. No problems found in the diff: the new cap is 16-aligned (the old min(u32::MAX - 0x10000) was not) and DATA_RVA + OFF_TEMPLATE + cap + 0xFFF stays below u32::MAX. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
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
xcl-dev/xcl!1393
No description provided.