This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
fixing ZipPackagePart.GetStreamCore crashes with NotSupportedException #40355
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.
Port #40319 to release/3.0
Fixes https://github.com/dotnet/corefx/issues/39816
Description
When trying to extract the stream from a
PackagePart
inCreate
mode,PackagePart.GetStream
unnecessarily throws an exception because the stream is not seekable. The underlying ZipArchiveEntry only ever supports opening once when the backing archive is inCreate
mode, so we shouldn't call SetLength in that case. You could still open an archive in `Update mode then call part.GetStream(FileMode.Create), in which case we'll want this call to SetLength, so we only avoid this call when the backing Archive is in Create mode.Customer Impact
This is a behavioral change between the old .NET Framework implementation of
System.IO.Packaging
that resided in WindowsBase, and the implementation in .NET Core. Customers trying to update their existing WPF applications will be broken by this. This issue was originally filed due to a regression it caused in WPF: dotnet/wpf#1363Regression?
This is a regression from .NET Framework, but has been the behavior in .NET Core since 1.0.
Risk
Very low. The fix avoids an unnecessary call to
SetLength
on a non-seekable stream.