Conversation
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.
Stream.Readis allowed to return fewer bytes than asked for, andStreamIOtreated a short read as the end of the stream. Three places acted on that assumption:ReadBytes/ReadBytesAsyncthrewEndOfStreamExceptionwhenever one call came back short, even with the data still sitting in the stream. They now loop until the buffer is full and throw only on a genuine zero-byte read.ReadAsyncis the one that makes this reachable in ordinary use — a network or compressed stream frequently returns less than asked.stream.Length— a property a non-seekable stream is entitled to throw on — and then read it in a single call, keeping whatever that call happened to return. It now usesCopyTo, and only touchesPositionon a stream that can seek.GetBytes,GetBytesAsyncandLookBytesrestored the caller's position after the read, so a read that threw left the object parked at the requested offset. The restore is in afinallynow.Three tests, all of which fail on
masterand pass here:ReadBytesCompletesPartialReadsReadBytesAsyncCompletesPartialReadsConstructorBuffersANonSeekablePartialReadStreamLengthSuite: 143 passed / 0 failed on
net9.0andnet48. Reverting onlyStreamIO.csand keeping the tests gives exactly 3 failures, so the tests measure the fix rather than the code around it.Found while reading DWG files through ACadSharp, where
StreamIOsits under the section readers.🤖 Generated with Claude Code
https://claude.ai/code/session_01Tw5VCqpDMFiQZ67K3rQ1eB