mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 23:50:51 +01:00
[PR #2058] runtime: guard stack region wrap/underflow and null inputs in thread_stacks #2064
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#2064
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/2058
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:rt/thread-stacks-bounds-and-wrap-guards📝 Commits (1)
0bba07bruntime: guard stack region wrap/underflow and null inputs in thread_stacks📊 Changes
2 files changed (+38 additions, -13 deletions)
View changed files
📝
runtime/src/thread_stacks.cpp(+29 -11)📝
runtime/test/thread_stacks_test.cpp(+9 -2)📄 Description
Claim ID:
RT-THREAD-STACKS-BOUNDS-AND-WRAP-GUARDSSummary
Hardens stack-region arithmetic, pointer bounds checks, and null-argument handling in
runtime/src/thread_stacks.cpp:top - stack.originalunderflow incopy_context_and_stack(): Checksregion.RegionSize > 0 && region.RegionSize <= UINT64_MAX - baseandstack.original >= base && top > stack.originalbefore computingtop - stack.originaland callingReadProcessMemory. Previously, a zero/wrappingRegionSizeortop <= stack.originalunderflowedtop - stack.originalnearUINT64_MAXand requested an 8 MiBReadProcessMemory.in_copy()check inwalk_copy(): Rewritesaddress - stack.copy + sizeof(DWORD64) <= stack.sizeasstack.size >= sizeof(DWORD64) && address >= stack.copy && address - stack.copy <= stack.size - sizeof(DWORD64)so addition cannot wrap.StackSampler::sample()now returns0immediately on nullthreadorframes;start_thread_stacks()checksGetModuleHandleWnon-null beforeGetProcAddress;thread_label()clampswcslen(description)toINT_MAXbefore casting toint.runtime/test/thread_stacks_test.cppwith null-handle / null-framesStackSampler::sample()checks andparse_stack_timeszero/overflow (4294967296) token checks.Verification
runtime/src/thread_stacks.cppwith minimal Win32 stubs; Windows MSVC CI run ofthread_stackspending)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: PASS (failures=0)clang++ -std=c++20 -O2 -Wall -Wextra -Werror: PASS (failures=0)main: failed bothtop <= stack.originalunderflow andBaseAddress + RegionSizewraparound assertions (ReadProcessMemorycalled with bogus length,main_exit=1).python3 -I scripts/check_no_game_data.pyclean;python3 -I tests/test_text_write_line_endings.py(3/3 OK).🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.