zip-rs / zip-old

Zip implementation in Rust
MIT License
731 stars 204 forks source link

Can't distinguish between files and directories with the same name that are extracted? #376

Closed San-greal closed 4 months ago

San-greal commented 1 year ago

The zip format file is generated with the following code:

let path = Path::new("test.zip");
let file = File::create(path).unwrap();

let mut zip = ZipWriter::new(file);
let options = FileOptions::default().compression_method(Zstd);
zip.start_file("test", options).unwrap();
zip.write_all(b"Hello, World!\n").unwrap();
zip.write_all(b"Hello, World!\n").unwrap();
zip.add_directory("test/test1", options).unwrap();
zip.finish().unwrap();

The unzip operation is performed by:

let mut file = File::open("test.zip").unwrap();
let mut archive = zip::ZipArchive::new(file).unwrap();
archive.extract("C:\\Users\\Desktop\\untitled\\src").unwrap();

So the following results appear: image

There is no problem when the directory created is not test/test1, for example a/test1 is correct. Is this caused by the inability to distinguish between files and directories?

ryanavella commented 10 months ago

Am I understanding correctly that the error only happens during unzipping, when trying to create both a test file and a test/ directory?

I'm fairly certain most mainstream OS+filesystem combinations don't allow this. On Unix-like systems, directories are just another kind of file, so this would be like trying to name two files the same thing.