zstd-rs
zstd-rs copied to clipboard
`Decoder` hangs on corrupted input
Hi,
I'm not sure if there is a solution for this but when I'm reading zstd
files that are corrupted (i.e. zstd -d myfile.zst
returns Decoding error (36) : Corrupted block detected
) I would expect the Decoder
to somehow signal end of file or something.
As it is now it gets stuck and uses 100% CPU instead.
Is there a workaround for this issue?
This is an specific example of code that gets stuck given that the file is corrupted:
let zf = BufReader::new(zstd::Decoder::new(File::open(log_file)?)?);
for line in zf.lines() {
// ...
}
Thanks!
Hi, and thanks for the report!
This sounds like a bug indeed. Do you happen to have the corrupted file that causes this issue?
See https://github.com/gyscos/zstd-rs/issues/182
Turns out the Decoder
reports an error, but .lines()
just returns this error in a loop in the iteration.
If you actually unwrap or return any error you get there, it would stop iterating.
Thanks for finding the root cause!