dignifiedquire / async-tar

A tar archive reading/writing library for async Rust.
Apache License 2.0
68 stars 52 forks source link

[BUG] Attempt to subtract with overflow #5

Closed teoxoy closed 4 years ago

teoxoy commented 4 years ago

I am using this code snippet to extract some files from an archived stream.

let mut ar = async_tar::Archive::new(stream_reader);
let mut entries = ar.entries()?;
use futures::stream::StreamExt;
while let Some(Ok(mut file)) = entries.next().await {
    if file
        .path()?
        .to_str()
        .map(|path| path.starts_with("some_path/"))
        .unwrap_or(false)
    {
        file.unpack_in(out_dir).await?;
    }
}

I am getting this error thread 'main' panicked at 'attempt to subtract with overflow' here: https://github.com/dignifiedquire/async-tar/blob/0739f53aaf805f493d3952adb7d1456b5ac6715e/src/archive.rs#L361

Relevant stacktrace snippet:

13: core::panicking::panic
            at src/libcore/panicking.rs:52
14: async_tar::archive::poll_next_raw
            at /home/my_user/.cargo/registry/src/github.com-1ecc6299db9ec823/async-tar-0.1.1/src/archive.rs:356
15: <async_tar::archive::Entries<R> as futures_core::stream::Stream>::poll_next
            at /home/my_user/.cargo/registry/src/github.com-1ecc6299db9ec823/async-tar-0.1.1/src/archive.rs:271
16: futures_util::stream::stream::StreamExt::poll_next_unpin
            at /home/my_user/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.5/src/stream/stream/mod.rs:1323
17: <futures_util::stream::stream::next::Next<St> as core::future::future::Future>::poll
            at /home/my_user/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.5/src/stream/stream/next.rs:35
18: std::future::poll_with_tls_context
            at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd/src/libstd/future.rs:102
19: backend_app::download::{{closure}}
            at src/main.rs:513

I can see that some files are being extracted successfully but somewhere around the end of the archive, my program crashes with that error and not all files have been extracted.

dignifiedquire commented 4 years ago

Any chance you could provide me with an example file that triggers this?

teoxoy commented 4 years ago

You can try with this archive Here is also the code snippet I'm using to download, decompress and untar (including the commented async-tar code at the end)

dignifiedquire commented 4 years ago

Thank you for that, I managed to reproduce and fix finally.

teoxoy commented 4 years ago

Thanks for fixing it, works like a charm now. Do you have an ETA for the next release?

dignifiedquire commented 4 years ago

just published 0.1.2