From c5a70e68014a3428f935e3eafb10d65f58e1352b Mon Sep 17 00:00:00 2001 From: DecDuck Date: Fri, 21 Aug 2026 10:20:14 +1000 Subject: [PATCH] Fix archive backend crash (#475) * Fix archive backend * Fix overflow bug + add workflow * Potential fix for pull request finding 'CodeQL / Workflow does not contain permissions' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Fix lint --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- .github/workflows/torrential-ci.yml | 57 +++++++++++++++++++ libraries/droplet/src/lib.rs | 2 + .../droplet/src/versions/archive_backend.rs | 4 +- torrential/src/server/mod.rs | 2 +- 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/torrential-ci.yml diff --git a/.github/workflows/torrential-ci.yml b/.github/workflows/torrential-ci.yml new file mode 100644 index 00000000..22f5898e --- /dev/null +++ b/.github/workflows/torrential-ci.yml @@ -0,0 +1,57 @@ +name: Torrential CI + +on: + push: + branches: [develop] + paths: + - "torrential/**" + - "libraries/droplet/**" + - "libraries/droplet_types/**" + - "libraries/libarchive/**" + - ".github/workflows/torrential-ci.yml" + pull_request: + branches: [develop] + paths: + - "torrential/**" + - "libraries/droplet/**" + - "libraries/droplet_types/**" + - "libraries/libarchive/**" + - ".github/workflows/torrential-ci.yml" + workflow_dispatch: + +permissions: + contents: read + +env: + CARGO_TERM_COLOR: always + +jobs: + ci: + name: Build & Test + runs-on: ubuntu-latest + defaults: + run: + working-directory: torrential + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@nightly + + - name: Rust cache + uses: swatinem/rust-cache@v2 + with: + workspaces: "./torrential -> target" + + # Required by the droplet-rs path dependency (libarchive bindings). + - name: Install libarchive + run: | + sudo apt-get update + sudo apt-get install -y libarchive-dev + + - name: Build + run: cargo build --all-targets --verbose + + - name: Run tests + run: cargo test --verbose diff --git a/libraries/droplet/src/lib.rs b/libraries/droplet/src/lib.rs index 2331bbda..79055a86 100644 --- a/libraries/droplet/src/lib.rs +++ b/libraries/droplet/src/lib.rs @@ -1,4 +1,6 @@ #![deny(clippy::all)] +// `#[async_trait]` emits `#[must_use]` on futures that are already `#[must_use]`, tripping `double_must_use`. +#![allow(clippy::double_must_use)] #![feature(impl_trait_in_bindings)] pub mod file_utils; pub mod manifest; diff --git a/libraries/droplet/src/versions/archive_backend.rs b/libraries/droplet/src/versions/archive_backend.rs index 01d27476..d8bf45dd 100644 --- a/libraries/droplet/src/versions/archive_backend.rs +++ b/libraries/droplet/src/versions/archive_backend.rs @@ -41,8 +41,8 @@ impl AsyncRead for ArchiveReader { ) -> std::task::Poll> { if let Some(block) = &mut self.prev_block { let to_read = buf.remaining().min(block.len()); - let result = block.split_off(to_read); - buf.put_slice(&result); + buf.put_slice(&block[..to_read]); + block.drain(..to_read); // If the block is empty, we can read more if block.is_empty() { diff --git a/torrential/src/server/mod.rs b/torrential/src/server/mod.rs index e98ce058..e35626ab 100644 --- a/torrential/src/server/mod.rs +++ b/torrential/src/server/mod.rs @@ -161,7 +161,7 @@ impl DropServer { { let mut mutex_lock = self.write_stream.lock().await; - mutex_lock.write(&buf.len().to_le_bytes()).await?; + mutex_lock.write_all(&buf.len().to_le_bytes()).await?; mutex_lock.write_all(&buf).await?; };