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

Can't unpack zero sized file created by dotnet tar #347

Open
sobczyk opened this issue Nov 20, 2023 · 1 comment
Open

Can't unpack zero sized file created by dotnet tar #347

sobczyk opened this issue Nov 20, 2023 · 1 comment

Comments

@sobczyk
Copy link

sobczyk commented Nov 20, 2023

Dotnet Tar creates empty files that cause error in tar-rs

Program.cs (preferably use .net 8)

using System.Formats.Tar;

MemoryStream ms = new(0);
var testStream = File.OpenWrite("trigger.tar");
TarWriter archive = new(testStream);
PaxTarEntry entry = new(TarEntryType.RegularFile, "zeroed");
entry.DataStream = ms;
archive.WriteEntry(entry);
archive.Dispose();
testStream.Dispose();

rust code:

use std::fs::File;
use tar::Archive;

fn main() {
    let file = File::open("trigger.tar").unwrap();
    let mut archive = Archive::new(file);
    let entries = archive.entries().unwrap();
    for entry in entries {
        let entry = entry.unwrap();
        println!("{:?}", entry.header());
    }
}

what I get:

thread 'main' panicked at src/main.rs:9:27:
called `Result::unwrap()` on an `Err` value: Custom { kind: Other, error: "numeric field was not a number:  when getting size for zeroed" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

example expected: ( "trigger.tar" created using GNU tar)

GnuHeader { entry_size: 0, size: 0, path: "zeroed", link_name: None, mode: 664, uid: 1000, gid: 1000, mtime: 1700484015, username: Some("sobczyk"), groupname: Some("sobczyk"), cksum: 5276, cksum_valid: true, is_extended: false, sparse: [] }
@sobczyk
Copy link
Author

sobczyk commented Nov 20, 2023

tar-rs-347-tarbug.tar.gz

I attach a test project directory
Use:

dotnet run
cargo run

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

No branches or pull requests

1 participant