Skip to content

Infinite archive compression if output file is inside of the input folder #287

@marcospb19

Description

@marcospb19

Version

385a630 (main branch)

Description

When compressing an archive like .tar, if the output file is inside of the input folder, Ouch enters an infinite compression state.

That's because the output is being considered as the output, so any written bytes are read again, and again, and that's an infinite loop.

Current Behavior

$ ouch compress . archive.tar

Runs forever and will slowly exhaust all your hard drive space.

Example compressing a 2 GB folder:
image

Expected Behavior

Ouch should ignore the output as the input file, like tar util does.

$ tar -cvf archive.tar .
...
...
tar: ./out.tar: file is the archive; not dumped

Additional Information

There is a check for skipping input files that are the same as the output file at

ouch/src/commands/mod.rs

Lines 406 to 419 in 385a630

fn deduplicate_input_files(files: &mut Vec<PathBuf>, output_path: &Path) {
let mut idx = 0;
while idx < files.len() {
if files[idx] == output_path {
warning!(
"The output file and the input file are the same: `{}`, skipping...",
output_path.display()
);
files.remove(idx);
} else {
idx += 1;
}
}
}
.

But in this case it's necessary to check while iterating in folder structures.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions