alexcrichton / tar-rs

Tar file reading/writing for Rust
https://docs.rs/tar
Apache License 2.0
616 stars 178 forks source link

Doesn't work correctly when entries are collected into a Vec #344

Open KSXGitHub opened 8 months ago

KSXGitHub commented 8 months ago

Steps to reproduce

  1. Clone this repo: https://github.com/KSXGitHub/tar-rs-bug-collect-entries-343
  2. Run reproduce.bash

Expected behavior

It prints the content of the files correctly.

Actual behavior

It prints empty strings as content.

ChewingBever commented 8 months ago

Note that care must be taken to consider each entry within an archive in sequence. If entries are processed out of sequence (from what the iterator returns), then the contents read for each entry may be corrupted.

As the docs state in the description of the entries function, you cannot process the entries out of order., which is what you are doing. You have to process the entries one by one from what the iterator returns.

This isn't a bug, it's expected behavior.

namse commented 7 months ago

In my case, tar always read file's content as empty.

For example, when I save the content as Hello, but it shows '\0\0\0\0\0'.

assertion `left == right` failed
  left: "\0\0\0\0\0"
 right: "Hello"
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

So I guess it's not a problem to use collect, but I think there are some problem with in-memory source?

-- edited

Nevermind my case, it become ok when I use for-loop instead of collect.