Fix ReusableStringStream to access the container under the lock#3031
Merged
horenmar merged 1 commit intocatchorg:develfrom Sep 25, 2025
dunhor:devel
Merged
Fix ReusableStringStream to access the container under the lock#3031horenmar merged 1 commit intocatchorg:develfrom dunhor:devel
horenmar merged 1 commit intocatchorg:develfrom
dunhor:devel
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## devel #3031 +/- ##
=======================================
Coverage 90.77% 90.77%
=======================================
Files 201 201
Lines 8707 8707
=======================================
Hits 7903 7903
Misses 804 804 🚀 New features to boost your workflow:
|
Contributor
Author
|
Hmm. I applied the patch to our build, but now ASan happened to hit a double free. I'll need to investigate this some more. |
Contributor
Author
Woops, I'm dumb. The thread support needs to be explicitly enabled. Still, this is a legitimate bug since concurrent access to the vector is unsafe as another thread can be calling |
Member
|
Thanks, I completely missed the potential for resize when figuring out where to take the lock. |
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.
Description
Commit 582200a made
ReusableStringStream's index reservation thread safe, however it's still accessing them_streamsvector outside the lock. This makes it so that theaddcall returns the pointer in addition to the index so that the lock doesn't need to get acquired again until destruction.The issue with accessing
m_streamsoutside the lock is thataddcan callpush_backon the vector, which might re-allocate. If this re-allocation occurs concurrently with anther thread trying to index into this array, you get UB (typically a null pointer read).