diff --git a/Cargo.lock b/Cargo.lock index a8bb96793..38da68d4e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -270,25 +270,16 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "async_io_utilities" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b20cffc5590f4bf33f05f97a3ea587feba9c50d20325b401daa096b92ff7da0" -dependencies = [ - "tokio", -] - [[package]] name = "async_zip" -version = "0.0.9" +version = "0.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a36d43bdefc7215b2b3a97edd03b1553b7969ad76551025eedd3b913c645f6e" +checksum = "c50d29ab7e2f9e808cca1a69ea56a36f4ff216f54a41a23aae1fd4afc05cc020" dependencies = [ "async-compression", - "async_io_utilities", - "chrono", "crc32fast", + "log", + "pin-project", "thiserror", "tokio", ] diff --git a/Cargo.toml b/Cargo.toml index 75ba85a77..4ce82ee35 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,7 @@ async-channel = "1.8.0" async-imap = { git = "https://github.com/async-email/async-imap", branch = "master", default-features = false, features = ["runtime-tokio"] } async-native-tls = { version = "0.5", default-features = false, features = ["runtime-tokio"] } async-smtp = { version = "0.9", default-features = false, features = ["runtime-tokio"] } -async_zip = { version = "0.0.9", default-features = false, features = ["deflate"] } +async_zip = { version = "0.0.11", default-features = false, features = ["deflate", "fs"] } backtrace = "0.3" base64 = "0.21" bitflags = "1.3" diff --git a/src/webxdc.rs b/src/webxdc.rs index d5873df55..07d7da54a 100644 --- a/src/webxdc.rs +++ b/src/webxdc.rs @@ -165,6 +165,19 @@ pub(crate) struct StatusUpdateItemAndSerial { max_serial: StatusUpdateSerial, } +/// Returns an entry index and a reference. +fn find_zip_entry<'a>( + file: &'a async_zip::ZipFile, + name: &str, +) -> Option<(usize, &'a async_zip::StoredZipEntry)> { + for (i, ent) in file.entries().iter().enumerate() { + if ent.entry().filename() == name { + return Some((i, ent)); + } + } + None +} + impl Context { /// check if a file is an acceptable webxdc for sending or receiving. pub(crate) async fn is_webxdc_file(&self, filename: &str, file: &[u8]) -> Result { @@ -180,7 +193,7 @@ impl Context { return Ok(false); } - let archive = match async_zip::read::mem::ZipFileReader::new(file).await { + let archive = match async_zip::read::mem::ZipFileReader::new(file.to_vec()).await { Ok(archive) => archive, Err(_) => { info!(self, "{} cannot be opened as zip-file", &filename); @@ -188,7 +201,7 @@ impl Context { } }; - if archive.entry("index.html").is_none() { + if find_zip_entry(archive.file(), "index.html").is_none() { info!(self, "{} misses index.html", &filename); return Ok(false); } @@ -215,7 +228,7 @@ impl Context { let valid = match async_zip::read::fs::ZipFileReader::new(path).await { Ok(archive) => { - if archive.entry("index.html").is_none() { + if find_zip_entry(archive.file(), "index.html").is_none() { info!(self, "{} misses index.html", filename); false } else { @@ -649,10 +662,9 @@ fn parse_webxdc_manifest(bytes: &[u8]) -> Result { } async fn get_blob(archive: &mut async_zip::read::fs::ZipFileReader, name: &str) -> Result> { - let (i, _) = archive - .entry(name) + let (i, _) = find_zip_entry(archive.file(), name) .ok_or_else(|| anyhow!("no entry found for {}", name))?; - let mut reader = archive.entry_reader(i).await?; + let mut reader = archive.entry(i).await?; let mut buf = Vec::new(); reader.read_to_end(&mut buf).await?; Ok(buf) @@ -754,9 +766,9 @@ impl Message { } else { self.get_filename().unwrap_or_default() }, - icon: if archive.entry("icon.png").is_some() { + icon: if find_zip_entry(archive.file(), "icon.png").is_some() { "icon.png".to_string() - } else if archive.entry("icon.jpg").is_some() { + } else if find_zip_entry(archive.file(), "icon.jpg").is_some() { "icon.jpg".to_string() } else { WEBXDC_DEFAULT_ICON.to_string()