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.
Fixes System.Drawing.Image.FromStream(...) throws "Parameter is not valid." when Stream.Read does not return full file length #14705
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
base: main
Are you sure you want to change the base?
Fixes System.Drawing.Image.FromStream(...) throws "Parameter is not valid." when Stream.Read does not return full file length #14705
Changes from all commits
fa5865cFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
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.
Behavioral note: this change makes
ComManagedStream.Readblock until the fullcbbytes are available or EOF is reached. This wrapper backs allIStreamconsumers (clipboard, drag/drop, OLE, GDI+), not just image decoding, so for a blocking/network-backed stream a caller that previously received a prompt short read will now be held until the entire request can be satisfied. This is the correct fix for GDI+, but worth confirming it's acceptable for the other callers.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.
Per the
ISequentialStream::Read/IStream::Readcontract, when fewer bytes thancbare returned because the end of the stream was reached, the method should returnS_FALSE(with*pcbRead < cb) rather thanS_OK. Now that this method deliberately reads until the buffer is full or EOF, a short result is a meaningful EOF signal. Since the whole point of this fix is that some COM callers are strict about read results, a strict caller that inspects the HRESULT (rather than justpcbRead) could still misbehave. Considerreturn read < buffer.Length ? HRESULT.S_FALSE : HRESULT.S_OK;. (The previous single-read code also returnedS_OK, so this is pre-existing, but the fix makes it more relevant.)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.
Unlike
Read_StreamReturnsShortReads_FillsBuffer(which assertsdestinationBuffer.Should().Equal(sourceBytes)), this test only verifies the returned byte count. Consider also asserting that the firstsourceBytes.Lengthbytes ofdestinationBufferequalsourceBytes, so the test confirms the data is correctly assembled across chunks up to EOF, not just that the count is right.Uh oh!
There was an error while loading. Please reload this page.