VULKAN-SCRATCH-ALIGN-OVERFLOW: avoid uint64 overflow when aligning chunk.used #520
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!520
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/520/head"
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?
@xroneyaa on GitHub · 2026-11-24 06:52 UTC · original
xroneyaa:fix/vulkan-scratch-align-overflow→main· +31 −6 · 2 files · 1 commits · merged 2026-11-24 14:37 UTCClaimed in the coordination issue as: VULKAN-SCRATCH-ALIGN-OVERFLOW
What and why
In
runtime/src/vulkan_scratch.h,ScratchBuffers::getroundedchunk.usedup to a 256-byte boundary with:When
chunk.used > UINT64_MAX - 255,chunk.used + alignment - 1wraps arounduint64_tandstartbecomes0, passingstart <= chunk.size && bytes <= chunk.size - startand returning offset0inside an already occupied chunk.This computes the alignment padding cleanly (
rem = chunk.used % alignment; pad = rem ? alignment - rem : 0) and checkspad <= chunk.size - chunk.usedbefore formingstart = chunk.used + padand checkingbytes <= chunk.size - start. It also adds a regression case toruntime/test/vulkan_scratch_test.cppverifying aUINT64_MAX - 100byte allocation followed by a16byte allocation spills to a second chunk rather than wrapping to offset0in chunk 1.Tested
vulkan_scratch_testwith MSVC 19.50 / Ninja (0 warnings under/W4)ctest --test-dir runtime/build --output-on-failure -R "^vulkan_scratch$"-> 1/1 Passed (0.01 s)python -I scripts/check_no_game_data.py runtime/src/vulkan_scratch.h runtime/test/vulkan_scratch_test.cpp-> exit 0GPUs tested: n/a (
vulkan_scratchruns CPU-only with fake device procs)AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed (n/a — no translator rule added).@kawaii-shakal on GitHub · 2026-11-24 07:47 UTC · original
Tested
aab57e15bon Linux (g++ 16.2, CPU only, public Vulkan-Headers v1.4.313). No defect found.runtime/test/vulkan_scratch_test.cppbuilt with ASan and UBSan passes. With the PR's basevulkan_scratch.hit fails at the new check (buf2 != buf1 && off2 == 0), so the test catches the wrap.used,sizeandbytesaround 0, 256, 2^32 andUINT64_MAX. In the 60 where the oldused + alignment - 1wrapped, the new code never returns an offset belowused. In every other case both give the same accept/refuse result and the same offset.Not tested: Windows, MSVC, a real Vulkan device.
Review written by Claude (Claude Code, Opus 5.5), an AI agent, posted from a contributor's account.