runtime: guard window-fit zero dimensions, signed overflow, and OOM in lifecycle shim #2054
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2054"
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 IlyassRS3 on 2026-11-25T19:06:14Z.
Claim ID:
RT-LIFECYCLE-FIT-WINDOW-BOUNDS-AND-OVERFLOWSummary
Hardens window fitting, centering, and registration in
runtime/shims/lifecycle.cpp:fit_window_to_area(): Extreme aspect ratios (e.g.,4000x2or2x4000into a1000x1000work area) previously truncated the minor axis to0, passing a zero-width or zero-height window toCreateWindowEx. Clamping both fitted axes to[1, min(area_span, INT_MAX)]guarantees valid non-zero dimensions that fit inside the work area while preserving exact results for normal aspect ratios (3840x2160->1848x1040).fit_window_to_area()andprepare_title_window()now computearea.right - area.left,area.bottom - area.top, and centered(x, y)coordinates instd::int64_tbefore clamping toint.register_app_state_change(): Skip ID0ifg_next_reg_idever wraps so a registration handle never collides withnullptr, and catchstd::bad_alloc->ERROR_NOT_ENOUGH_MEMORYinstead of unwinding a C++ exception acrossWINAPI.runtime/test/lifecycle_test.cppwith extreme wide/tall aspect ratio, wide virtual-desktop span (> INT_MAX), and empty work-area checks.Verification
runtime/shims/lifecycle.cppwith minimal Win32/shim stubs; Windows MSVC CI run oflifecyclepending)clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werror: PASS (failures=0)clang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werror(4 threads x 500 concurrent register/unregister + suspend dispatch + window fit/centering): PASS (failures=0)clang++ -std=c++20 -O2 -Wall -Wextra -Werror: PASS (failures=0)mainunder UBSan: triggeredruntime error: signed integer overflow: 2000000000 - -2000000000 cannot be represented in type 'LONG'atlifecycle.cpp:208and failed all 4 new assertions (main_exit=1).python3 -I scripts/check_no_game_data.pyclean;python3 -I tests/test_text_write_line_endings.py(3/3 OK).Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T19:06:26Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T11:28:35Z.
Verified on Windows 11 (
10.0.26200.9974) with MSVC19.44.35228(x64,/std:c++20 /EHsc /W4 /permissive- /utf-8 /O2) againstmain4a54aedcb+892f62708(claim#2570#issuecomment-7238486276):runtime/shims/lifecycle.cpp,runtime/test/lifecycle_test.cpp); widensarea_w/area_hand centering math toint64_twithintclamping, clamps scaled window axes to>= 1, skips0ong_next_reg_idwraparound, and catchesstd::bad_alloc->ERROR_NOT_ENOUGH_MEMORY.check_no_game_data.pyclean.4a54aedcb+ PR test):lifecycle_test.exefails (rc=1,34 check(s), 3 failure(s)on extreme wide/tall minor-axis clamping and >32-bit work-area span overflow).4a54aedcb+892f62708merge): Merges cleanly (rc=0), compiles with0/W4warnings, andlifecycle_test.exepasses (34 check(s), 0 failure(s),rc=0).AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T18:14:02Z.
Red/green: On main lifecycle_test fails 3 checks (extreme aspect ratios and a work area wider than signed 32 bits are mishandled), and with the PR ctest -R "^lifecycle$" passes.
Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main
c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T21:59:11Z.
Verified by OreoFR
c1ecf04ed+ PR head892f62708; green run in a merge package of 16 PRs, no new ctest failure vs mainctest -R "^lifecycle$"AI-assisted (Claude Code, Claude Opus 5.5).