-
Notifications
You must be signed in to change notification settings - Fork 18k
archive/zip: produces incorrect zip archives #30627
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
Comments
If you are running on Windows, then It sounds like you are suggesting that the archive/zip package should automatically change backslashes to slashes. I don't see why that would be a good idea. The default behavior should be that the package trusts the user. |
And by trusting the user there will be some errors like in my case. And luckily that the user does not have any bad intentions :) |
Here is an extraction from Zip specification: |
If that is what the zip spec says, I would be open to having zip return an error if the filename has backslashes. I do not think that archive/zip should convert backslashes to forward slashes. |
CC @dsnet |
Two things. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I am using the archive/zip library in order to produce a zip archive from a given directory. In that directory I have nested directory structures. The problem comes when I build the archive, I am walking each element in the given directory and am I writing it to the zip archive. If the currently walking path element is a dir, I just add a os.PathSeparator to the header's Name.
When the build is finished and I start to read the zip, I see that the files which are read contain "\" - backslashes - default PathSeparator for Windows. As the ZIP Spec defines, each path separator in the ZIP should be a '/' - leading slash.
I saw that description in the FileHeader struct:
In my opinion, the library should take care of
\\
- back slashes not the developer of the code :)Tell me what do you think about this.
Do you accept PRs and fixes about such small changes?
What did you expect to see?
A zip archive containing only '/' as path separators
What did you see instead?
On windows I see the following path separators '\'
The text was updated successfully, but these errors were encountered: