Skip to content
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

Behavior change regarding seekability of streams returned for ZipArchive #585

Closed
ojhad opened this issue Apr 15, 2019 · 10 comments · Fixed by #1311
Closed

Behavior change regarding seekability of streams returned for ZipArchive #585

ojhad opened this issue Apr 15, 2019 · 10 comments · Fixed by #1311
Assignees
Labels
Bug Product bug (most likely) rank20 Rank: Priority/rank on a scale of (1..100) regression status: This issue is a regression from a previous build or release
Milestone

Comments

@ojhad
Copy link
Contributor

ojhad commented Apr 15, 2019

  • .NET Core Version: 3.0.100-preview4

Problem description:

There is a behavior change regarding the seekability of returned ZipArchiveEntry streams.

.NET Framework behavior:

The WindowsBase implementation of Zip had the necessary functionality that operated on the returned deflate streams which provided support for seeking (However, in doing so, it incurred a lot of extra CPU and file system usage)

.NET Core behavior:
The current implementation in CoreFX (System.IO.Packaging) no longer provides this functionality, resulting in streams that are being returned to be non-seekable.

Related Issue:
https://github.com/dotnet/corefx/issues/34219

@grubioe grubioe added Enhancement Requested Product code improvement that does NOT require public API changes/additions Bug Product bug (most likely) and removed Enhancement Requested Product code improvement that does NOT require public API changes/additions labels Apr 18, 2019
@grubioe grubioe added this to the Preview milestone Apr 18, 2019
@grubioe grubioe added the regression status: This issue is a regression from a previous build or release label Apr 18, 2019
@grubioe grubioe added this to Needs Triage in .NET Core 3.0 May 10, 2019
@jbartlau
Copy link

I'm also having an issue with this exception if I call

var document = new XpsDocument(@"repro.xps", FileAccess.Read);
var paginatorSource = (IDocumentPaginatorSource)document.GetFixedDocumentSequence();

on the attached XPS file (which was created with the XPS Document Writer driver). See my comment at #575. Exception details:

System.NotSupportedException
  HResult=0x80131515
  Message=This operation is not supported.
  Source=System.IO.Compression
  StackTrace:
   at System.IO.Compression.DeflateStream.get_Position()
   at System.IO.Packaging.ZipWrappingStream.get_Position()
   at MS.Internal.IO.Packaging.SynchronizingStream.get_Position() in /_/src/Microsoft.DotNet.Wpf/src/shared/MS/Internal/IO/SynchronizingStream.cs:line 207
   at MS.Internal.IO.Packaging.DeobfuscatingStream.Read(Byte[] buffer, Int32 offset, Int32 count) in /_/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/Internal/IO/Packaging/DeobfuscatingStream.cs:line 56
   at MS.Internal.FontCache.FontSource.StreamToByteArray(Stream fontStream) in /_/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/Internal/FontCache/FontSource.cs:line 419
   at MS.Internal.FontCache.FontSource.GetUnmanagedStream() in /_/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/Internal/FontCache/FontSource.cs:line 279
   at MS.Internal.Text.TextInterface.FontFileStream..ctor(IFontSource fontSource)
   at MS.Internal.Text.TextInterface.FontFileLoader.CreateStreamFromKey(Void* fontFileReferenceKey, UInt32 fontFileReferenceKeySize, IntPtr* fontFileStream)

repro.zip

@vatsan-madhavan
Copy link
Member

@grubioe - we need to document this issue as a change, and remove this from our queue. likely this is not going to actionable.

@grubioe grubioe added the Documentation Documentation bug or enhancement, does not impact product or test code label Jun 25, 2019
@grubioe grubioe self-assigned this Jun 25, 2019
@jbartlau
Copy link

@vatsan-madhavan This will break Xps viewing and printing in a wide range of scenarios. IMHO this should be looked at at least for the Core 3.0 release.

@weltkante
Copy link

weltkante commented Jun 26, 2019

@vatsan-madhavan you have at least one more internal caller in WPF which is broken, see stack of @jbartlau, all internal callers need to be fixed

@jbartlau
Copy link

@weltkante @vatsan-madhavan Would be happy to raise a separate issue in order to tackle the internal call there.

@vatsan-madhavan
Copy link
Member

@weltkante, @jbartlau, we are still looking into this. @jbartlau's issue (#1063) is helpful.

@vatsan-madhavan vatsan-madhavan added rank20 Rank: Priority/rank on a scale of (1..100) and removed Documentation Documentation bug or enhancement, does not impact product or test code labels Jul 16, 2019
@weltkante
Copy link

weltkante commented Jul 17, 2019

@vatsan-madhavan the stack trace over in #1063 looks different than what @jbartlau reported, it seems to be a native exception and not directly related to the zip archive issue here and with @jbartlau.

@rladuca rladuca self-assigned this Jul 17, 2019
@rladuca rladuca modified the milestones: Future, 3.0 Jul 17, 2019
@rladuca
Copy link
Member

rladuca commented Jul 18, 2019

There is a working solution to this in branch, should be PRed later today: https://github.com/dotnet/wpf/tree/dev/roladuca/wrappackagestreams.

In summary, the DeflateStream implementation in System.IO.Compression is a non-seekable stream. This is returned to PackagePart.GetStream when it is opened as read-only. In these scenarios, we need to copy out the stream to a MemoryStream in order to be able to use Seek and Position. This is the essence of the fix that @stevenbrix did, but this attempts to address all such usages.

As a workaround (@jbartlau) you can open the Package as read/write (or XPS document, whatever API you are using). When you do this, the underlying packaging and compression APIs already uncompress to a MemoryStream and return that. So in those instances, we're given a proper seekable stream and things will work.

@jbartlau
Copy link

As a workaround (@jbartlau) you can open the Package as read/write (or XPS document, whatever API you are using).

Thanks @rladuca, can confirm the workaround is viable, will test the fix once it becomes available in one of the next previews then.

@weltkante
Copy link

Writing streams may need another look, wrapping them in MemoryStream needs special care to ensure the writes actually make it to the original stream and aren't lost when disposing the MemoryStream.

(Related to #1363 which is an example for actually writing and got me thinking about this case!)

@ghost ghost locked as resolved and limited conversation to collaborators Apr 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Product bug (most likely) rank20 Rank: Priority/rank on a scale of (1..100) regression status: This issue is a regression from a previous build or release
Projects
No open projects
.NET Core 3.0
Needs Triage
Development

Successfully merging a pull request may close this issue.

7 participants