arena_size: a negative LEONIDA_ARENA_MB clamps to the 16 MiB floor, not the 4095 MiB maximum (ARENA-NEGATIVE-MB) #923

Manually merged
github merged 1 commit from gh-pr/923/head into gh-pr/923/base 2026-11-26 09:28:28 +00:00
Owner

@⁠TuroYT on GitHub · 2026-11-24 15:12 UTC · original
TuroYT:fix/arena-negative-mb → main · +7 −1 · 2 files · 1 commits · merged 2026-11-24 21:26 UTC

Claimed in the coordination issue as: ARENA-NEGATIVE-MB (#14)

What was wrong

runtime/src/arena_size.h:63 parsed LEONIDA_ARENA_MB with std::strtoull. A negative number wraps to a huge
unsigned value, so std::clamp returned the 4095 MiB maximum. The header comment documents a clamp to 16..4095 MiB,
and a negative number should reach the 16 MiB floor.

Reproduction on origin/main (g++ 16, -std=c++20 -fsanitize=address,undefined, a probe calling
decide_arena_size with an empty ArenaLimits):

[-5] -> 4095 MiB
[-1] -> 4095 MiB
[-0] -> 16 MiB
[ -5] -> 4095 MiB
[-99999999999999999999] -> 4095 MiB
[99999999999999999999] -> 4095 MiB
[abc] -> 16 MiB
[+20] -> 20 MiB
[0x20] -> 16 MiB
[99999] -> 4095 MiB

What changed

  • runtime/src/arena_size.h: parse with std::strtoll and clamp as a signed value before converting to
    VkDeviceSize. Negative text now reaches the 16 MiB floor. Every other input keeps its result.
  • runtime/test/arena_size_test.cpp: three new checks in request_without_limits: "-5" gives 16 MiB,
    "-99999999999999999999" gives 16 MiB, "99999999999999999999" gives 4095 MiB.

Tested

  • g++ -std=c++20 -Wall -Wextra -fsanitize=address,undefined -I runtime/src -I <dir with vulkan/ and vk_video/> runtime/test/arena_size_test.cpp then run the binary: builds with no warnings, prints the summary line, exit 0.
  • Same command with clang++: exit 0. It prints three -Wmissing-field-initializers warnings from
    query_arena_limits (lines 34 to 36), which this change does not touch.
  • Same test built against the origin/main header: fails with line 32: decide_arena_size("-5", none).bytes == 16 * MiB, exit 1.
  • The probe above on the fixed header: -5, -1, -0, -5, -99999999999999999999 and abc give 16 MiB;
    99999999999999999999 and 99999 give 4095 MiB; +20 gives 20 MiB; 0x20 gives 16 MiB.
  • python3 -I scripts/check_no_game_data.py runtime/src/arena_size.h runtime/test/arena_size_test.cpp: exit 0.
  • git diff --check: clean.

Not tested

  • The Windows build and the CTest registration of arena_size on Windows.
  • ctest on Linux for the whole runtime tree (only the single test file was built and run).
  • A GPU run, and the real environment path through runtime/shims/d3d12_vulkan_device.cpp.
  • The new checks against the origin/main header ran one at a time through the probe. The test stops at its first
    failing check (line 32), so the huge-negative check was not reached by the test binary on the unfixed header.

AI-assisted (Claude Code).

**@⁠TuroYT** on GitHub · 2026-11-24 15:12 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/923) `TuroYT:fix/arena-negative-mb` → `main` · +7 −1 · 2 files · 1 commits · merged 2026-11-24 21:26 UTC Claimed in the coordination issue as: ARENA-NEGATIVE-MB (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) ## What was wrong `runtime/src/arena_size.h:63` parsed `LEONIDA_ARENA_MB` with `std::strtoull`. A negative number wraps to a huge unsigned value, so `std::clamp` returned the 4095 MiB maximum. The header comment documents a clamp to 16..4095 MiB, and a negative number should reach the 16 MiB floor. Reproduction on `origin/main` (g++ 16, `-std=c++20 -fsanitize=address,undefined`, a probe calling `decide_arena_size` with an empty `ArenaLimits`): ``` [-5] -> 4095 MiB [-1] -> 4095 MiB [-0] -> 16 MiB [ -5] -> 4095 MiB [-99999999999999999999] -> 4095 MiB [99999999999999999999] -> 4095 MiB [abc] -> 16 MiB [+20] -> 20 MiB [0x20] -> 16 MiB [99999] -> 4095 MiB ``` ## What changed - `runtime/src/arena_size.h`: parse with `std::strtoll` and clamp as a signed value before converting to `VkDeviceSize`. Negative text now reaches the 16 MiB floor. Every other input keeps its result. - `runtime/test/arena_size_test.cpp`: three new checks in `request_without_limits`: `"-5"` gives 16 MiB, `"-99999999999999999999"` gives 16 MiB, `"99999999999999999999"` gives 4095 MiB. ## Tested - `g++ -std=c++20 -Wall -Wextra -fsanitize=address,undefined -I runtime/src -I <dir with vulkan/ and vk_video/> runtime/test/arena_size_test.cpp` then run the binary: builds with no warnings, prints the summary line, exit 0. - Same command with `clang++`: exit 0. It prints three `-Wmissing-field-initializers` warnings from `query_arena_limits` (lines 34 to 36), which this change does not touch. - Same test built against the `origin/main` header: fails with `line 32: decide_arena_size("-5", none).bytes == 16 * MiB`, exit 1. - The probe above on the fixed header: `-5`, `-1`, `-0`, ` -5`, `-99999999999999999999` and `abc` give 16 MiB; `99999999999999999999` and `99999` give 4095 MiB; `+20` gives 20 MiB; `0x20` gives 16 MiB. - `python3 -I scripts/check_no_game_data.py runtime/src/arena_size.h runtime/test/arena_size_test.cpp`: exit 0. - `git diff --check`: clean. ## Not tested - The Windows build and the CTest registration of `arena_size` on Windows. - `ctest` on Linux for the whole runtime tree (only the single test file was built and run). - A GPU run, and the real environment path through `runtime/shims/d3d12_vulkan_device.cpp`. - The new checks against the `origin/main` header ran one at a time through the probe. The test stops at its first failing check (line 32), so the huge-negative check was not reached by the test binary on the unfixed header. AI-assisted (Claude Code).
strtoull("-5") wraps to 2^64-5, so decide_arena_size clamped it to the
4095 MiB maximum. strtoll clamps "-5" and "-99999999999999999999" to the
16 MiB floor, as the header comment documents.
Adds checks for "-5", the huge negative and the huge positive to
arena_size_test. Other inputs keep their results.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:28:25 +00:00
github manually merged commit 49e6392c9e into gh-pr/923/base 2026-11-26 09:28:28 +00:00
Author
Owner

@⁠KernelSmoker on GitHub · 2026-11-24 15:17 UTC · original · approved these changes

Reviewed exact head 49e6392c9e6ee45cfce8ef7b690aaa7fc223ce0d. Parsing LEONIDA_ARENA_MB as signed prevents negative values from wrapping through strtoull; clamping occurs in MiB bounds before conversion to VkDeviceSize, and overflow values still clamp to the documented floor/ceiling. The added negative and overflow cases cover the regression. I built and ran runtime/test/arena_size_test.cpp in the Fedora 45 tool container using GCC 16 with -std=c++20 -Wall -Wextra -Werror -pedantic; it passed and printed the expected summary. I could not independently link the sanitizer variant because this tool image lacks libubsan; this is an environment limitation. No GPU/game data used.

**@⁠KernelSmoker** on GitHub · 2026-11-24 15:17 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/923#pullrequestreview-6042004405) · **approved these changes** Reviewed exact head `49e6392c9e6ee45cfce8ef7b690aaa7fc223ce0d`. Parsing `LEONIDA_ARENA_MB` as signed prevents negative values from wrapping through `strtoull`; clamping occurs in MiB bounds before conversion to `VkDeviceSize`, and overflow values still clamp to the documented floor/ceiling. The added negative and overflow cases cover the regression. I built and ran `runtime/test/arena_size_test.cpp` in the Fedora 45 tool container using GCC 16 with `-std=c++20 -Wall -Wextra -Werror -pedantic`; it passed and printed the expected summary. I could not independently link the sanitizer variant because this tool image lacks `libubsan`; this is an environment limitation. No GPU/game data used.
Author
Owner

@⁠QemmHD on GitHub · 2026-11-24 21:26 UTC · original

Merging.

Why merged: ARENA-NEGATIVE-MB: LEONIDA_ARENA_MB is parsed with strtoll, so a negative value clamps to the 16 MiB floor instead of wrapping around to the 4095 MiB maximum. KernelSmoker approved this exact head.

Why it's good: A 3-line parse change. arena_size passes both plain and under validation.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main 66d4f5aa3, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative of this batch (13 PRs) on main 0b45fdc21: the repo-consistency set gives 573 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 314/316 with the same 11 skips. The only failures are main's: d3d12_depth_resolve (pre-existing) and d3d12_close_parity (the #510 regression, fixed by #1286). All d3d12_* tests under validation show 0 VUIDs. git merge-tree against current main 6261ca916: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠QemmHD** on GitHub · 2026-11-24 21:26 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/923#issuecomment-7144929852) Merging. **Why merged:** ARENA-NEGATIVE-MB: LEONIDA_ARENA_MB is parsed with strtoll, so a negative value clamps to the 16 MiB floor instead of wrapping around to the 4095 MiB maximum. KernelSmoker approved this exact head. **Why it's good:** A 3-line parse change. arena_size passes both plain and under validation. Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main 66d4f5aa3, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative of this batch (13 PRs) on main 0b45fdc21: the repo-consistency set gives 573 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 314/316 with the same 11 skips. The only failures are main's: d3d12_depth_resolve (pre-existing) and d3d12_close_parity (the #510 regression, fixed by #1286). All d3d12_* tests under validation show 0 VUIDs. git merge-tree against current main 6261ca916: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes. AI-assisted (Claude Code, Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.