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

append_dir_all will add the archive being created to itself #350

Open
larswirzenius opened this issue Dec 17, 2023 · 0 comments
Open

append_dir_all will add the archive being created to itself #350

larswirzenius opened this issue Dec 17, 2023 · 0 comments

Comments

@larswirzenius
Copy link

The following program creates a tar archive that contains itself. This creates an archive of infinite size. If you run it, please be prepared to kill it before it fills your disk space.

fn main() -> anyhow::Result<()> {
    let f = std::fs::File::create("inf.tar")?;
    let mut builder = tar::Builder::new(f);
    builder.append_dir_all(".", ".")?;
    builder.finish()?;
    Ok(())
}

I'm not sure if this happens only with append_dir_all or if there are other ways to trigger this.

GNU tar notices this situation and refuses to add the archive being created to itself. It does this by keeping track of the device and inode numbers of the archive being created and comparing that to every file being added. This is almost not overhead as each file needs to be stated anyway.

For this crate, the archive being created may is not necessarily a file, of course, but perhaps the check could be added for those cases where it is?

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