fix(archive): handle mangled zip file names properly

Replace enclosed_name with mangled_name fallback for robustness.
This commit is contained in:
ttyS3 2024-09-06 15:26:23 +00:00 committed by João Marcos
parent 9c69fbd911
commit 9e1c30bb86

View File

@ -124,27 +124,25 @@ where
let (tx, rx) = mpsc::channel();
thread::spawn(move || {
for idx in 0..archive.len() {
let maybe_file_in_archive = (|| {
let file_in_archive = (|| {
let zip_result = match password.clone() {
Some(password) => archive
.by_index_decrypt(idx, password.as_bytes()).ok()?
.by_index_decrypt(idx, password.as_bytes())?
.map_err(|_| zip::result::ZipError::UnsupportedArchive("Password required to decrypt file")),
None => archive.by_index(idx),
};
let file = match zip_result {
Ok(f) => f,
Err(e) => return Some(Err(e.into())),
Err(e) => return Err(e.into()),
};
let path = file.enclosed_name()?.to_owned();
let path = file.enclosed_name().unwrap_or(&*file.mangled_name()).to_owned();
let is_dir = file.is_dir();
Some(Ok(FileInArchive { path, is_dir }))
Ok(FileInArchive { path, is_dir })
})();
if let Some(file_in_archive) = maybe_file_in_archive {
tx.send(file_in_archive).unwrap();
}
tx.send(file_in_archive).unwrap();
}
});