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

Cannot add file named \ #743

Open
nwalters512 opened this issue Mar 7, 2024 · 2 comments
Open

Cannot add file named \ #743

nwalters512 opened this issue Mar 7, 2024 · 2 comments

Comments

@nwalters512
Copy link

nwalters512 commented Mar 7, 2024

Consider the following code:

const archiver = require('archiver');

const archive = archiver('zip');

archive.append('hello, world!', { name: '\\' });

This is meant to add a file named \ to the archive. According to the specification (https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT), this should be allowed, and it's certainly allowed by standard implementations of the zip command (that is, touch '\' && zip -r test.zip '\' works as expected and produces an archive containing a single file \).

However, what happens in practice is that this fails with the following error message:

ArchiverError: entry name must be a non-empty string value

This happens because of the following line:

data.name = util.sanitizePath(data.name);

Which in turn runs this:

https://github.com/archiverjs/archiver-utils/blob/695387cdc4816a3d19edb6f1d5473e6395479567/index.js#L91-L93

sanitizePath transforms \ into the empty string.

The same underlying problem causes a different issue with the following code:

archive.append('hello, world!', { name: 'testing/\\' });

In this case, the name is transformed to testing/, which incorrectly results in the creation of a directory instead of a file with the specified contents.

One more example:

archive.append('hello, world!', { name: 'testing/foo\\bar.txt' });

This actually creates testing/foo/bar.txt, which is not at all what was intended.

@ctalkington
Copy link
Member

I think some of those concerns came from cross OS pathing issues. does the \ file actually extract on say windows? or is it unaccessible?

@nwalters512
Copy link
Author

Unfortunately I don't have access to a Windows machine to test it on. I imagine the behavior could vary between different tools on Windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants