zstd-rs icon indicating copy to clipboard operation
zstd-rs copied to clipboard

`Decoder` hangs on corrupted input

Open korken89 opened this issue 2 years ago • 1 comments

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!

korken89 avatar May 10 '22 07:05 korken89

Hi, and thanks for the report!

This sounds like a bug indeed. Do you happen to have the corrupted file that causes this issue?

gyscos avatar May 11 '22 17:05 gyscos

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.

gyscos avatar Dec 12 '22 15:12 gyscos

Thanks for finding the root cause!

korken89 avatar Dec 17 '22 07:12 korken89