alexcrichton / tar-rs

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

Unpacking file size is incorrect (with reproduced repo) #286

Open axetroy opened 2 years ago

axetroy commented 2 years ago

And here is the reproduced repo: https://github.com/axetroy/libflate-66

git clone https://github.com/axetroy/libflate-66
cd ./libflate-66
cargo run ./

# View unpacked files ’prune‘

The origin file size is : 985,384 The unzip file size is : 965,416

  1. unpack with Tar

size = 965,416

  1. unpack with python3

size = 985,384

>>> import tarfile
>>> tar = tarfile.open("prune_darwin_amd64.tar")
>>> tar.getmember("prune").size
985384
  1. unpack with build-in tar tools in macOS

size = 985,384

ref: https://github.com/sile/libflate/issues/66

alexcrichton commented 2 years ago

Running locally:

$ cargo run -q --example raw_list < ./prune_darwin_amd64.tar
-------------------------- Entry 0
path: PaxHeader/prune
size: 128
entry size: 128
link name: None
file type: 0x78
mode: 0o755
uid: 501
gid: 20
mtime: 1645982337
username: Some("runner")
groupname: Some("staff")
kind: UStar
pax extensions:
        "mtime" = "1645982337.98713127"
        "GNU.sparse.major" = "1"
        "GNU.sparse.minor" = "0"
        "GNU.sparse.name" = "prune"
        "GNU.sparse.realsize" = "985384"
-------------------------- Entry 1
path: GNUSparseFile.0/prune
size: 965416
entry size: 965416
link name: None
file type: 0x30
mode: 0o755
uid: 501
gid: 20
mtime: 1645982337
username: Some("runner")
groupname: Some("staff")
kind: UStar

It appears that this is using a pax extension for the real size that isn't supported by this crate.

axetroy commented 2 years ago

Did you say that the Tar format is incorrect?

What do I need to do?

axetroy commented 2 years ago

Before resolving this, I decompressed executable files that have lost some information and cannot be executed.

And my temporary solution:

Priority use the TAR command in the system to decompress

NobodyXu commented 2 years ago

I think #298 will fix this.