Skip to content

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

Merged
QemmHD merged 1 commit into
ProjectLeonida:mainfrom
TuroYT:fix/arena-negative-mb
Nov 24, 2026
Merged

QemmHD merged 1 commit into
ProjectLeonida:mainfrom
TuroYT:fix/arena-negative-mb

Conversation

@TuroYT

@TuroYT TuroYT commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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

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).

…or (ARENA-NEGATIVE-MB)

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.

@KernelSmoker KernelSmoker left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@QemmHD

QemmHD commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

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 66d4f5a, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative of this batch (13 PRs) on main 0b45fdc: 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 6261ca9: 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
QemmHD merged commit 5237898 into ProjectLeonida:main Nov 24, 2026
7 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants