-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SequenceReader contains invalid volatile memory access patterns #45379
Comments
A possible fix:
|
SequenceReader is a
The |
Good point. I'm trying to remember why it's a ref struct since it doesn't contain any byref fields. If it's intended to be a ref struct, then yeah, we can kill all of the volatile goop. |
From #27522
So it's intentional to prevent this?! |
Except this one 😉 public ReadOnlySpan<T> CurrentSpan { readonly get; private set; } |
Aaaargh. I hate that it's buried with other properties and isn't grouped with the fields at the top of the file. |
Then it sounds like @gfoidl's suggestion is the best one. Find places in |
@GrabYourPitchforks are you working on this? Otherwise I can have a look.
That should be done in the same PR. |
I wouldn't change the layout of the file as part of this PR. Just lamenting generally. 😞 |
This was the only occurance --> #45437 (hope it's an easy review 😉). |
Thanks @gfoidl and @adamsitnik for handling this! :) |
See code:
runtime/src/libraries/System.Memory/src/System/Buffers/SequenceReader.cs
Lines 97 to 108 in c8a97ff
Accesses to the _length field are not guaranteed atomic on 32-bit platforms without going through the Volatile or Interlocked APIs. While the write is protected by such a guard, the read is not. This could result in the _length backing field being torn and the Length property returning an incorrect value on 32-bit platforms.
The text was updated successfully, but these errors were encountered: