tl;dr a archive.tar with a label, i.e. tar --label my-label -cf archive.tar ..., will fail to iterate over entries
Reproduction
Given these project files
main.rs
use std::env;
use std::fs::File;
use std::io;
use tar::Archive;
fn run() -> Result<(), Box<dyn std::error::Error>> {
let mut args = env::args();
let program_name = args.next().unwrap_or_else(|| "tar_bug_1".to_string());
let tar_path = match (args.next(), args.next()) {
(Some(path), None) => path,
_ => {
eprintln!("Usage: {program_name} <path-to-tar-file>");
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"expected exactly one argument",
)
.into());
}
};
let file = File::open(&tar_path)?;
let mut archive = Archive::new(file);
eprintln!("archive.entries()...");
let entry_iter: tar::Entries<File> = match archive.entries() {
Ok(val) => val,
Err(err) => {
eprintln!("archive.entries() Err; {:?}", err);
return Err(err.into());
}
};
eprintln!("for entry_result in entry_iter...");
for entry_result in entry_iter {
let entry = match entry_result {
Ok(val) => val,
Err(err) => {
eprintln!("entry_result Err; {:?}", err);
continue;
}
};
let path = entry.path()?;
println!("{}", path.display());
}
eprintln!("Ok");
Ok(())
}
fn main() {
if let Err(err) = run() {
eprintln!("Error: {err}");
std::process::exit(1);
}
}
Cargo.toml
[package]
name = "tar_bug_1"
version = "0.1.0"
edition = "2024"
[dependencies]
tar = "0.4.44"
steps
Create the file archive.tar with a label and some files
$ echo "A" > a.txt
$ echo "BB" > b.txt
$ tar -v -c --label MY_TAR_LABEL -f archive.tar ./a.txt ./b.txt
MY_TAR_LABEL
./a.txt
./b.txt
Print the entries in archive.tar
$ cargo run -- ./archive.tar
archive.entries()...
for entry_result in entry_iter...
Error: numeric field was not a number: when getting size for MY_TAR_LABEL
Ok
ERROR: the iteration over archive.entries() ceases
ACTUAL: the iteration over archive.entries() to be able to continue
sanity check program
Test with a tar file without a label, just to be sure the program works for other tar files
$ tar -v -c -f archive_no_label.tar ./a.txt ./b.txt
./a.txt
./b.txt
$ cargo run -- ./archive_no_label.tar
archive.entries()...
for entry_result in entry_iter...
./a.txt
./b.txt
Ok
Observed environment
- Ubuntu 24
- crate tar 0.4.44
- GNU tar 1.35
- rust 1.91.0
tl;dr a
archive.tarwith a label, i.e.tar --label my-label -cf archive.tar ..., will fail to iterate over entriesReproduction
Given these project files
main.rsCargo.tomlsteps
Create the file
archive.tarwith a label and some filesPrint the entries in
archive.tarERROR: the iteration over
archive.entries()ceasesACTUAL: the iteration over
archive.entries()to be able to continuesanity check program
Test with a tar file without a label, just to be sure the program works for other tar files
Observed environment