From dd125f142a996771d52485650c520b5519531cd9 Mon Sep 17 00:00:00 2001 From: link2xt Date: Thu, 10 Oct 2024 11:06:03 +0000 Subject: [PATCH 1/2] chore(cargo): upgrade async_zip to 0.0.17 --- Cargo.lock | 14 ++++++++------ Cargo.toml | 2 +- src/webxdc.rs | 20 +++++++++++--------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 99ccd0c9ba..b11f2a8870 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -273,15 +273,15 @@ dependencies = [ [[package]] name = "async-compression" -version = "0.3.15" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942c7cd7ae39e91bde4820d74132e9862e62c2f386c3aa90ccf55949f5bad63a" +checksum = "998282f8f49ccd6116b0ed8a4de0fbd3151697920e7c7533416d6e25e76434a7" dependencies = [ "flate2", "futures-core", + "futures-io", "memchr", "pin-project-lite", - "tokio", ] [[package]] @@ -368,16 +368,17 @@ dependencies = [ [[package]] name = "async_zip" -version = "0.0.12" +version = "0.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2105142db9c6203b9dadc83b0553394589a6cb31b1449a3b46b42f47c3434d0" +checksum = "00b9f7252833d5ed4b00aa9604b563529dd5e11de9c23615de2dcdf91eb87b52" dependencies = [ "async-compression", "crc32fast", - "log", + "futures-lite 2.3.0", "pin-project", "thiserror", "tokio", + "tokio-util", ] [[package]] @@ -6074,6 +6075,7 @@ checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" dependencies = [ "bytes", "futures-core", + "futures-io", "futures-sink", "futures-util", "hashbrown", diff --git a/Cargo.toml b/Cargo.toml index 6bb52a9e99..8dc3fe888f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,7 +44,7 @@ async-channel = { workspace = true } async-imap = { version = "0.10.1", 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.12", default-features = false, features = ["deflate", "fs"] } +async_zip = { version = "0.0.17", default-features = false, features = ["deflate", "tokio-fs"] } base64 = { workspace = true } brotli = { version = "6", default-features=false, features = ["std"] } bytes = "1" diff --git a/src/webxdc.rs b/src/webxdc.rs index e0c38b1440..a769af94f9 100644 --- a/src/webxdc.rs +++ b/src/webxdc.rs @@ -29,7 +29,6 @@ use lettre_email::PartBuilder; use rusqlite::OptionalExtension; use serde::{Deserialize, Serialize}; use serde_json::Value; -use tokio::io::AsyncReadExt; use crate::chat::{self, Chat}; use crate::constants::Chattype; @@ -195,7 +194,7 @@ fn find_zip_entry<'a>( name: &str, ) -> Option<(usize, &'a async_zip::StoredZipEntry)> { for (i, ent) in file.entries().iter().enumerate() { - if ent.entry().filename() == name { + if ent.filename().as_bytes() == name.as_bytes() { return Some((i, ent)); } } @@ -212,7 +211,7 @@ impl Context { return Ok(false); } - let archive = match async_zip::read::mem::ZipFileReader::new(file.to_vec()).await { + let archive = match async_zip::base::read::mem::ZipFileReader::new(file.to_vec()).await { Ok(archive) => archive, Err(_) => { info!(self, "{} cannot be opened as zip-file", &filename); @@ -235,7 +234,7 @@ impl Context { bail!("{} is not a valid webxdc file", filename); } - let valid = match async_zip::read::fs::ZipFileReader::new(path).await { + let valid = match async_zip::tokio::read::fs::ZipFileReader::new(path).await { Ok(archive) => { if find_zip_entry(archive.file(), "index.html").is_none() { warn!(self, "{} misses index.html", filename); @@ -791,12 +790,15 @@ fn parse_webxdc_manifest(bytes: &[u8]) -> Result { Ok(manifest) } -async fn get_blob(archive: &async_zip::read::fs::ZipFileReader, name: &str) -> Result> { +async fn get_blob( + archive: &async_zip::tokio::read::fs::ZipFileReader, + name: &str, +) -> Result> { let (i, _) = find_zip_entry(archive.file(), name) .ok_or_else(|| anyhow!("no entry found for {}", name))?; - let mut reader = archive.entry(i).await?; + let mut reader = archive.reader_with_entry(i).await?; let mut buf = Vec::new(); - reader.read_to_end(&mut buf).await?; + reader.read_to_end_checked(&mut buf).await?; Ok(buf) } @@ -806,12 +808,12 @@ impl Message { async fn get_webxdc_archive( &self, context: &Context, - ) -> Result { + ) -> Result { let path = self .get_file(context) .ok_or_else(|| format_err!("No webxdc instance file."))?; let path_abs = get_abs_path(context, &path); - let archive = async_zip::read::fs::ZipFileReader::new(path_abs).await?; + let archive = async_zip::tokio::read::fs::ZipFileReader::new(path_abs).await?; Ok(archive) } From e8db9a931d0ae411f3db5d28049c63760dc03437 Mon Sep 17 00:00:00 2001 From: link2xt Date: Thu, 10 Oct 2024 22:59:51 +0000 Subject: [PATCH 2/2] FsZipFileReader --- src/webxdc.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/webxdc.rs b/src/webxdc.rs index a769af94f9..8dacd778cc 100644 --- a/src/webxdc.rs +++ b/src/webxdc.rs @@ -23,6 +23,7 @@ use std::path::Path; use anyhow::{anyhow, bail, ensure, format_err, Context as _, Result}; +use async_zip::tokio::read::fs::ZipFileReader as FsZipFileReader; use deltachat_contact_tools::sanitize_bidi_characters; use deltachat_derive::FromSql; use lettre_email::PartBuilder; @@ -234,7 +235,7 @@ impl Context { bail!("{} is not a valid webxdc file", filename); } - let valid = match async_zip::tokio::read::fs::ZipFileReader::new(path).await { + let valid = match FsZipFileReader::new(path).await { Ok(archive) => { if find_zip_entry(archive.file(), "index.html").is_none() { warn!(self, "{} misses index.html", filename); @@ -790,10 +791,7 @@ fn parse_webxdc_manifest(bytes: &[u8]) -> Result { Ok(manifest) } -async fn get_blob( - archive: &async_zip::tokio::read::fs::ZipFileReader, - name: &str, -) -> Result> { +async fn get_blob(archive: &FsZipFileReader, name: &str) -> Result> { let (i, _) = find_zip_entry(archive.file(), name) .ok_or_else(|| anyhow!("no entry found for {}", name))?; let mut reader = archive.reader_with_entry(i).await?; @@ -805,15 +803,12 @@ async fn get_blob( impl Message { /// Get handle to a webxdc ZIP-archive. /// To check for file existence use archive.by_name(), to read a file, use get_blob(archive). - async fn get_webxdc_archive( - &self, - context: &Context, - ) -> Result { + async fn get_webxdc_archive(&self, context: &Context) -> Result { let path = self .get_file(context) .ok_or_else(|| format_err!("No webxdc instance file."))?; let path_abs = get_abs_path(context, &path); - let archive = async_zip::tokio::read::fs::ZipFileReader::new(path_abs).await?; + let archive = FsZipFileReader::new(path_abs).await?; Ok(archive) }