You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use a Zip file produced on a *nix system or MacOS (In this case)
Zip files with invalid windows characters that are valid on MacOS/Linux
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.
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
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?)
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.
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?)
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.
Activity
piksel commentedon May 22, 2019
Version 1.10? I'm guessing it's 1.1.0?
Numpsy commentedon 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
SharpZipLib/src/ICSharpCode.SharpZipLib/Zip/ZipEntry.cs
Line 163 in f03a2ef
piksel commentedon 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 commentedon 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 commentedon 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
ZipNameTransformfor the transforms.Also this might effect #402 as that presumes entry file names to be transformed.
Numpsy commentedon 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 commentedon 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 commentedon Aug 9, 2020
Hopefully resolved now?
piksel commentedon Aug 9, 2020
Yeah!