runtime: guard align_up_saturating against zero alignment and add unit tests (RT-XS-ALLOC-SIZE-GUARDS-AND-TESTS) #2027
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2027"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-25T18:30:04Z.
Claimed in the coordination issue as: RT-XS-ALLOC-SIZE-GUARDS-AND-TESTS (claim)
What and why
Guard
align_up_saturatingagainst zero alignment:runtime/shims/d3d12_xs_alloc_size.h:204,align_up_saturating(value, to)did not guard againstto == 0, leading to integer division by zero and underflow in(to - 1).if (to == 0) return value;to safely returnvalueunmodified when alignment is 0.Add comprehensive standalone CPU-only unit test
d3d12_xs_alloc_size_test:runtime/shims/d3d12_xs_alloc_size.hcomputes critical console render target and depth-stencil allocation sizing rules (SW_64KB tile padding, mip tail tile sharing, and multi-slice scaling) but had no direct unit test.runtime/test/d3d12_xs_alloc_size_test.cppexercising:align_up_saturating: zero alignment guard, standard rounding, power-of-two alignments, and saturation without wrapping nearUINT64_MAX.render_target_element_bytes: 1, 2, 4, 8, and 16-byte formats, plus 0 for non-RT formats.console_depth_planes: depth/stencil plane separation for D32S8, D24S8, console D16S8 (DXGI 118), D32, D16, and non-depth formats.console_render_target_size: dimension, flag, sample count, format, and extent validation; 1920x1080 4-byte target exact 135-tile computation (8,847,360 bytes); multi-slice arrays and full mip chains.console_depth_stencil_size: plane addition, flags/dimension validation, and sample count checks.console_placement: rejection of null descs and non-targets; placement calculations and offset/size reporting ineacharray for growing console render targets.d3d12_xs_alloc_size_testandd3d12_xs_alloc_sizeCTest inruntime/CMakeLists.txt.Tested
62/62 checks passed(0 failures).python -I tests/test_ci_registration.py: 16/16 pass.python -I tests/test_text_write_line_endings.py: 3/3 pass.python -I scripts/check_no_game_data.py: clean (0 violations, no game data).AI-assisted (Claude Code)
Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T11:51:51Z.
Verified on Windows 11 (
10.0.26200.9974) with MSVC19.44.35228(x64,/std:c++20 /EHsc /W4 /permissive- /utf-8 /O2) againstmain24549bdb1+065df3d8b(claim#2570#issuecomment-7238799031):runtime/CMakeLists.txt,runtime/shims/d3d12_xs_alloc_size.h,runtime/test/d3d12_xs_alloc_size_test.cpp); guardsalign_up_saturating(value, 0)against division by zero / wraparound and adds a 62-check unit test covering render-target/depth-stencil element sizes, planes, console tile padding, and placement.check_no_game_data.pyclean.24549bdb1+ PR test):d3d12_xs_alloc_size_test.exefails (rc=1,FAIL align_up_saturating with to=0 returns value,61/62 checks passed).24549bdb1+065df3d8bmerge): Auto-merges cleanly (rc=0), compiles with0warnings ind3d12_xs_alloc_size.h/d3d12_xs_alloc_size_test.cpp, and passes (62/62 checks passed,rc=0).AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T21:58:18Z.
Verified by OreoFR
Run 1 (lot 4)
09c153948+ PR head065df3d8b; integration package 4 of 6 (2 PRs, merged without conflict)Run 2 (lot 4 bis)
33db04a70+ PR head065df3d8b; integration package of 15 PRsAll runs
AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T12:56:39Z.
TAKEN by OreoFR (Windows, RTX 4070 8 GB)
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T15:31:27Z.
Verified by OreoFR — READY
3535eb5c4+ this PR (head065df3d8b) merged with --no-ff, no conflict (still none with mainc22a0a732). Main has changedruntime/shims/d3d12_xs_alloc_size.hsince the earlier runs (console_texture_layouttakes the title's layout word,console_placementpasses it), so this run checks the PR against that.d3d12_xs_alloc_size_testfails, rc=1,FAIL align_up_saturating with to=0 returns value, 61/62 checks.--repeat until-fail:3. On the merge, 12/12 passed. On main, the 11 that exist there still had 4 failures (big_compile_gate and api_ref_state timed out, xs_proxy_mock and file_system failed). New failures vs main: none.LEONIDA_CARGO=OFF,LEONIDA_XMA2_DECODER_LIBempty);dumpbin /importsidentical to main (25 DLLs, no WS2_32).to == 0, which used to divide by zero. Every call in the runtime passes a non-zero alignment, so runtime behaviour is unchanged. The new test usesconsole_placementthrough its current signature and builds against main's header.AI-assisted (Claude Code, Claude Opus 5.5), run for OreoFR.
Ready to merge per the maintainers' plan (green, no conflict, tested).
Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-29T18:28:56Z.
Thank you! Merged into
mainwith a merge commit. It was verified ready on its current head (065df3d8b) by OreoFR's Windows agent (RTX 4070, Windows 11: ctest and the gta6rt link without XMA); see the verification comment above. (AI-assisted, posted for DadaCap.)