Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panicked at 'attempt to add with overflow' #265

Closed
charlesxsh opened this issue Oct 4, 2021 · 2 comments · Fixed by #267
Closed

panicked at 'attempt to add with overflow' #265

charlesxsh opened this issue Oct 4, 2021 · 2 comments · Fixed by #267

Comments

@charlesxsh
Copy link

For given input file:

in.zip
with following code:

fn main() {
    let filepath = "<input file>"
    let data = std::fs::read(filepath).unwrap();

    parse_tar(&data);
    
}

pub fn parse_tar(data: &[u8]) {
    use std::io::Cursor;

    let cursor = Cursor::new(data);
    let mut archive = tar::Archive::new(cursor);
    let entries = match archive.entries() {
        Ok(entries) => entries,
        Err(..) => return,
    };
    for entry in entries {
        if let Ok(mut entry) = entry {
            let _ = entry.path();
            let _ = entry.path_bytes();
            let _ = entry.link_name();
            let _ = entry.link_name_bytes();
            if let Ok(Some(mut extensions)) = entry.pax_extensions() {
                while let Some(Ok(extension)) = extensions.next() {
                    let _ = extension.key();
                    let _ = extension.key_bytes();
                    let _ = extension.value();
                    let _ = extension.value_bytes();
                }
            }
            let _ = entry.header().as_old();
            let _ = entry.header().as_ustar();
            let _ = entry.header().as_gnu();
            let _ = entry.header().as_bytes();
            let _ = entry.header().entry_size();
            let _ = entry.header().size();
            let _ = entry.header().path();
            let _ = entry.header().path_bytes();
            let _ = entry.header().link_name();
            let _ = entry.header().link_name_bytes();
            let _ = entry.header().mode();
            let _ = entry.header().uid();
            let _ = entry.header().gid();
            let _ = entry.header().mtime();
            let _ = entry.header().username();
            let _ = entry.header().username_bytes();
            let _ = entry.header().groupname();
            let _ = entry.header().groupname_bytes();
            let _ = entry.header().device_major();
            let _ = entry.header().device_minor();
            let _ = entry.header().entry_type();
            let _ = entry.header().cksum();
        }
    }
}

it has output:

thread 'main' panicked at 'attempt to add with overflow', /home/szx5097/.cargo/registry/src/github.com-1ecc6299db9ec823/tar-0.4.37/src/archive.rs:301:20
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: tar::archive::EntriesFields::next_entry_raw
             at /home/szx5097/.cargo/registry/src/github.com-1ecc6299db9ec823/tar-0.4.37/src/archive.rs:301:20
   4: tar::archive::EntriesFields::next_entry
             at /home/szx5097/.cargo/registry/src/github.com-1ecc6299db9ec823/tar-0.4.37/src/archive.rs:319:31
   5: <tar::archive::EntriesFields as core::iter::traits::iterator::Iterator>::next
             at /home/szx5097/.cargo/registry/src/github.com-1ecc6299db9ec823/tar-0.4.37/src/archive.rs:488:19
   6: <tar::archive::Entries<R> as core::iter::traits::iterator::Iterator>::next
             at /home/szx5097/.cargo/registry/src/github.com-1ecc6299db9ec823/tar-0.4.37/src/archive.rs:228:9
...
@charlesxsh
Copy link
Author

The input file is the file in the zip file, not zip file itself :)

@alexcrichton
Copy link
Owner

Thanks for the report! This should be fixed in #267

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants