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

Invalid Characters in Zip throws exception #341

Closed
RevenantBob opened this issue May 7, 2019 · 9 comments
Closed

Invalid Characters in Zip throws exception #341

RevenantBob opened this issue May 7, 2019 · 9 comments
Labels
bug zip Related to ZIP file format

Comments

@RevenantBob
Copy link

RevenantBob commented May 7, 2019

Steps to reproduce

  1. Use a Zip file produced on a *nix system or MacOS (In this case)
  2. Zip files with invalid windows characters that are valid on MacOS/Linux
  3. Open up Zip archive with SharpZipLib API

Exception is thrown.

Expected behavior

SharpZipLib should not load a ZipFile class and try to clean up the entry filenames before returning them to the user. The user should be responsible for cleaning up entries themselves in whatever method they see fit.

Actual behavior

SharpZipLib throws an exception in ZipEntry line 1303 because IsPathRooted checks for invalid characters. It also removes root path names.

Version of SharpZipLib

1.10

Obtained from (only keep the relevant lines)

  • Package installed using NuGet

For now I worked around the issues by removing the CleanName function from ZipEntry in my own local copy.

@piksel
Copy link
Member

piksel commented May 22, 2019

Version 1.10? I'm guessing it's 1.1.0?

@piksel piksel added bug zip Related to ZIP file format labels May 22, 2019
@Numpsy
Copy link
Contributor

Numpsy commented Jun 17, 2019

Confirmed with the current source using a zip file which contains a file that has question marks in the name - it throws a System.ArgumentException from Path.IsPathRooted.

Given that the comments on the CleanName function talk about converting names into zip formats, doesn't sound like something that should be called on extraction?
The ZipEntry constructor comment at

/// path elements separated by '/' characters. This is not enforced see <see cref="CleanName(string)">CleanName</see>
also says that the name format isn't enforced, so it might be misleading that the constructor chain does then call CleanName?

@piksel
Copy link
Member

piksel commented Jun 18, 2019

Agreed. It should at least be platform-specific, but then again, we could just let the file system throw the exception on invalid file names instead.

@Numpsy
Copy link
Contributor

Numpsy commented Jun 18, 2019

There's a bunch of functionality in the NameTransform bits for processing invalid characters and such that the caller and/or container could use rather than ZipEntry doing it, including some alternate path root handling code that CleanName could possibly use instead of IsPathRooted if required?

Related: Most of the Add() functions on ZipFile create ZipEntrys using the EntryFactory, which runs the names through NameTransform, but the variants that actually take ZipEntries don't.
Would removing the CleanName calls from the ZipEntry constructor then allow you to add entries with invalid names to ZipFile, in situations where you perhaps couldn't before? (or is that just up to the caller to deal with?)

@piksel
Copy link
Member

piksel commented Feb 1, 2020

Yeah, now with #362 closed, we will be able to read out-of-spec files, but it also makes it possible to create them. We should at least make sure that that's not done accidentally, and use ZipNameTransform for the transforms.
Also this might effect #402 as that presumes entry file names to be transformed.

@Numpsy
Copy link
Contributor

Numpsy commented Feb 2, 2020

Looks like the 'WriteZipStreamWithNoCompression' unit test you added for #406 has been broken by the transform/clean change?

Something like Numpsy@4e7b20b might work to transform the names when adding entries to ZipOutputStream, not sure how the instances need to be managed though (Might ZipOutputStream need a NameTransform property similar to the one on ZipFile?)

@Numpsy
Copy link
Contributor

Numpsy commented Feb 17, 2020

Saying that, making zip output stream do a transform itself would also have a knock on effect in FastZip (e.g. #275) - not sure how the interactions should work there.

@Numpsy
Copy link
Contributor

Numpsy commented Aug 9, 2020

Hopefully resolved now?

@piksel
Copy link
Member

piksel commented Aug 9, 2020

Yeah!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug zip Related to ZIP file format
Projects
None yet
Development

No branches or pull requests

3 participants