Release shared_mutex with unlock_shared() in Chunked3d::chunk_safe (UB)#1084
Open
robert-kofler42 wants to merge 1 commit into
Open
Release shared_mutex with unlock_shared() in Chunked3d::chunk_safe (UB)#1084robert-kofler42 wants to merge 1 commit into
robert-kofler42 wants to merge 1 commit into
Conversation
Chunked3d::chunk_safe() — the fast path that every volume voxel access in the tracer and renderer goes through (Chunked3dAccessor::get_chunk_safe -> chunk_safe) — takes the chunk-cache std::shared_mutex with lock_shared() but releases it with unlock() on both branches (ChunkedTensor.hpp:422, 425). Per [thread.sharedmutex.requirements], a lock acquired with lock_shared() must be released with unlock_shared(); calling unlock() while holding shared ownership is undefined behavior. libstdc++ happens to tolerate it (shared and exclusive ownership share a pthread_rwlock), which is why it went unnoticed on Linux, but it is broken on libc++ (macOS) and MSVC, and the repo targets macOS + Ubuntu. The other _mutex.lock()/unlock() pairs in the file are correct exclusive locks and are unchanged. Surfaced while running vc_grow_seg_from_seed on an open-data scroll volume under ThreadSanitizer; reading the flagged chunk-cache hot path revealed the mismatched unlock. Compile-verified; correctness is by the std::shared_mutex contract (same class as the GrowSurface unlock_shared fix).
|
Someone is attempting to deploy a commit to the scroll Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Chunked3d::chunk_safe()is the fast path that every volume voxel access in the tracer and renderer goes through (Chunked3dAccessor::get_chunk_safe→chunk_safe). It takes the chunk-cachestd::shared_mutexwithlock_shared()but releases it withunlock()on both branches:Per [thread.sharedmutex.requirements], a lock acquired with
lock_shared()must be released withunlock_shared(). Callingunlock()while holding shared ownership is undefined behavior. libstdc++ tolerates it (shared/exclusive ownership share onepthread_rwlock), which is why it went unnoticed on Linux, but it is broken on libc++ (macOS) and MSVC — and the repo targets macOS + Ubuntu. The other_mutex.lock()/unlock()pairs in the file are correct exclusive locks and are unchanged.Fix
Release the shared lock with
unlock_shared()on both branches (2 lines).How it was found
Surfaced while running
vc_grow_seg_from_seedon an open-data scroll volume (s3://vesuvius-challenge-open-data/, streamed) under ThreadSanitizer; reading the flagged chunk-cache hot path revealed the mismatched unlock. Compile-verified (vc_core+vc_tracer); correctness is by thestd::shared_mutexcontract — same class as the GrowSurfaceunlock_sharedfix (#1077), in a much hotter path.🤖 Generated with Claude Code