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

Revisit Seekability of writable zip streams #1364

Open
weltkante opened this issue Jul 24, 2019 · 4 comments
Open

Revisit Seekability of writable zip streams #1364

weltkante opened this issue Jul 24, 2019 · 4 comments
Labels
Bug Product bug (most likely)
Milestone

Comments

@weltkante
Copy link

weltkante commented Jul 24, 2019

In PR #1311 (issue #585) two writable streams (Certificate.cs and XmlDigitalSignatureProcessor.cs) get wrapped in a memory stream by calling the new method GetSeekableStream(FileMode.Create, FileAccess.Write). It is unclear from the PR source how the written data will be propagated to the actual zip stream. Since this was noticed after the PR merged I'm opening a separate issue to revisit the handling of writable streams.

I'd also argue that the current implementation of GetSeekableStream should not have had FileMode and FileAccess paramters, since the only case which is handled correctly is the open/read combination.

I'd suggest either providing a dedicated stream wrapper class and keeping FileMode/FileAccess, or remove FileMode/FileAccess and provide a separate code path for callers who want to write data.

Related: issue #1363 apparently still has call sites which do not get wrapped

@rladuca
Copy link
Member

rladuca commented Jul 24, 2019

@weltkante

This is not an issue as PackagePart.GetStream will return seekable streams when the stream is writeable.
The extension method GetSeekableStream already handles this case and will merely forward a seekable stream upward to the caller.

This is the reason that the workaround is to open your package as writeable.

@weltkante
Copy link
Author

I see, though #1363 still produced a non seekable stream for writing, so I worry that it can also happen in GetSeekableStream and pass through undetected, silently dropping data. This worry might be unfounded since we don't yet know the root cause of #1363 but it might be worth adding checks to ensure that GetSeekableStream never creates a MemoryStream wrapper when opening something as writable. Maybe throw an exception if this unexpected case ever happens, so that instead of silently dropping the data there is something to diagnose.

Your choice, if you think your tests cover this well enough to detect it if that ever regresses it might not be necessary.

@rladuca
Copy link
Member

rladuca commented Jul 24, 2019

I am entirely sympathetic to the more cautious approach. I'm going to root cause #1363 and figure out where that sits in relation to the changes.

I think your suggestion on testing write vs. seekability is a reasonable one and I'll leave this open as a conduit for potentially changing it.

@rladuca
Copy link
Member

rladuca commented Jul 24, 2019

@weltkante Be aware that I am not assigning this just yet, I'll let our normal triage process pick it up since by then I'll have more info.

@grubioe grubioe added this to the 3.0 milestone Jul 26, 2019
@grubioe grubioe added the Bug Product bug (most likely) label Jul 26, 2019
@grubioe grubioe modified the milestones: 3.0, 5.0 Aug 21, 2019
@rladuca rladuca removed their assignment Jan 23, 2020
@ryalanms ryalanms modified the milestones: 5.0.0, 7.0.0 Aug 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Product bug (most likely)
Projects
None yet
Development

No branches or pull requests

4 participants