-
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
Allow reading more than the minimum number when filling buffer in XmlBufferReader #72847
Allow reading more than the minimum number when filling buffer in XmlBufferReader #72847
Conversation
Read as much as possible into the buffer without limiting to minimum count
Performance or correctness? If the latter, what test can we add? |
cc: @eerhardt |
@@ -231,7 +231,7 @@ private bool TryEnsureBytes(int count) | |||
} | |||
int needed = newOffsetMax - _offsetMax; | |||
DiagnosticUtility.DebugAssert(needed > 0, ""); | |||
int read = _stream.ReadAtLeast(_buffer.AsSpan(_offsetMax, needed), needed, throwOnEndOfStream: false); | |||
int read = _stream.ReadAtLeast(_buffer.AsSpan(_offsetMax), needed, throwOnEndOfStream: false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prior to the change to use ReadAtLeast, this was also limiting how much was read to needed
. Is it possible changing it to read more could create bugs? For example, is it possible this might end up reading more from the stream that a consumer intended, such that it would erroneously consume something from the stream after what is being deserialized?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, I am thinking about closing this for now and maybe add a comment in a separate PR.
Is there any other reader which have any way around that (such as resetting the stream position) and if so how late (dispose or after each read) would it be ok to reset the position?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resetting position isn't always possible: many (most) streams don't support it.
We should just close this PR for now. Thanks, though.
Note, this code needs to use |
Read as much as possible into the buffer without limiting to minimum count
Affects at least XmlDictionaryReader
The current code looked a bit odd with ReadAtLeast while still limiting number of bytes read to the minimum number of bytes to read.