Release shared_mutex with unlock_shared() in GrowSurface loops (UB; breaks on macOS/libc++)#1077
Open
robert-kofler42 wants to merge 1 commit into
Conversation
…e loops optimize_surface_mapping and the grow loop take read critical sections with std::shared_mutex::lock_shared() but released them with unlock() instead of unlock_shared() (GrowSurface.cpp:1309, 1312, 2764). Per [thread.sharedmutex.requirements], a lock acquired with lock_shared() must be released with unlock_shared(); calling unlock() on a shared ownership is undefined behavior. libstdc++ happens to tolerate it, but libc++ (macOS) does not — it corrupts the lock state — and the repo targets macOS + Ubuntu. Change the three offending unlock() calls (the ones paired with lock_shared()) to unlock_shared(). The exclusive lock()/unlock() pairs in the same functions are correct and left unchanged.
|
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
optimize_surface_mappingand the grow loop inGrowSurface.cppguard read-only critical sections with astd::shared_mutexacquired vialock_shared(), but release it withunlock()instead ofunlock_shared():GrowSurface.cpp:1307lock_shared()→ released byunlock()at :1309 and :1312GrowSurface.cpp:2752lock_shared()→ released byunlock()at :2764Per [thread.sharedmutex.requirements], a lock acquired with
lock_shared()must be released withunlock_shared(). Callingunlock()while holding shared ownership is undefined behavior:unlock()corrupts the lock state — and this repo targets Ubuntu + macOS (a hard portability requirement inAGENTS.md).All other
lock()/unlock()pairs on this mutex are correct exclusive locks and are left unchanged.Fix
Change the three
unlock()calls that pair withlock_shared()tounlock_shared()(3 lines). The exclusive write sections (lock()/unlock()) are untouched.Verification
vc_corecompiles clean.std::shared_mutexcontract (standard-conformance fix), confirmed by inspecting every lock/unlock site on the mutex: after the change, the 2lock_shared()sites are released only viaunlock_shared()(3 release points across mutually-exclusive branches) and everylock()only viaunlock().vc_grow_seg_*), which requires scroll data to exercise end-to-end; this is a pure standard-conformance correction with no behavior change on libstdc++.