dstorage: harden staging_bytes overflow and StagingPool::Lease reuse (RT-DSTORAGE-STAGING-OVERFLOW-AND-REUSE) #2015
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2015"
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-25T18:11:14Z.
Claim:
RT-DSTORAGE-STAGING-OVERFLOW-AND-REUSE(claim comment#7170510712on #1608).Problem
In
runtime/shims/dstorage_staging.h:staging_bytes():pages()computedsize + sizeof(uint64_t) * (1 + (size - 1 + offset) / 65536)andstage()computedinput + outputwithout saturation, allowing extreme values to wrapuint64_tbelowStagingPool::limit.StagingPool::Leaseaccounting leak on reuse: callingtry_pair()oracquire()on aLeasethat already held a reservation overwrotebytes_without returning the previous reservation topool_.used_/pool_.helpers_, permanently leaking pool capacity and eventually deadlocking future waiters.notify_all()and%lluformat casts:acquire()and~Lease()calledpool_.changed_.notify_all()while still holdingpool_.mutex_(causing immediate lock re-contention in woken DirectStorage threads), and printeduint64_twith%lluwithout casting tounsigned long long.Fix
staging_bytes()pages()andstage()calculations saturating againstUINT64_MAX.held_inStagingPool::Lease: refuse duplicatetry_pair()while held, add explicitrelease()(called from~Lease()and before re-acquire()), and callnotify_all()after unlockingpool_.mutex_.pool_.peak_andlimittounsigned long longin tracestd::fprintfcalls.runtime/test/dstorage_test.cpp(test_staging_budget(), 0CMakeLists.txtedits) covering duplicatetry_pair,acquire(0)release, re-acquire, explicitrelease(), and largestaging_bytes()inputs.Verification
runtime/shims/dstorage_staging.h(including 4-thread concurrentStagingPoolstress tests and alltest_staging_budgetassertions) under minimal Win32 ABI stubs with:clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werrorclang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werrorclang++ -std=c++20 -O2 -Wall -Wextra -Werrorpython3 -I scripts/check_no_game_data.py runtime/shims/dstorage_staging.h runtime/test/dstorage_test.cppandpython3 -I tests/test_text_write_line_endings.py: all passed.Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T18:11:30Z.
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-28T12:24:15Z.
Verified on Windows 11 (
10.0.26200.9974) with MSVC19.44.35228(x64,/std:c++20 /EHsc /W4 /permissive- /utf-8 /O2) againstmaind48a957bb+435d7541fe(claim#2570#issuecomment-7239117859):runtime/shims/dstorage_staging.h,runtime/test/dstorage_test.cpp); saturates 64-bitstaging_bytespage-table and multi-stage sums, tracksLease::held_so duplicatetry_paircalls are refused andacquire(...)/acquire(0)/release()return any prior reservation cleanly, and moveschanged_.notify_all()outsidepool_.mutex_.check_no_game_data.pyclean.d48a957bb+ PR test): Fails to build (rc=2,Lease::release()absent onmain); withreclaimed.release()omitted,dstorage_test.exedeadlocks (TIMEOUT after 15s) when re-acquiring a heldLeaseleakspool_.used_.d48a957bb+435d7541femerge): Auto-merges cleanly (rc=0), compilesdstorage_staging.h/dstorage_test.cppwith0warnings, and passesdstorage_test.exe(rc=0).AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T17:54:40Z.
Red/green: On main dstorage_test does not compile (StagingPool::Lease::release is missing) and without that call it deadlocks re-acquiring a held Lease, and with the PR ctest -R "^dstorage$" 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:58:01Z.
Verified by OreoFR
c1ecf04ed+ PR head435d7541f; green run in a merge package of 16 PRs, no new ctest failure vs mainctest -R ^dstorage$AI-assisted (Claude Code, Claude Opus 5.5).