sile / libflate

A Rust implementation of DEFLATE algorithm and related formats (ZLIB, GZIP)
https://docs.rs/libflate
MIT License
178 stars 35 forks source link

libflate::gzip::Decoder::read does not handle zero-length buffer properly #61

Closed Hawk777 closed 3 years ago

Hawk777 commented 3 years ago

According to the documentation for the Read trait’s read function:

If n is 0, then it can indicate one of two scenarios:

  1. This reader has reached its “end of file”…
  2. The buffer specified was 0 bytes in length.

This suggests that it is legal to pass a zero-length buffer to read. However, if a zero-length buffer is passed to libflate::gzip::Decoder::read, then it will pass the buffer to the underlying self.reader, which will of course return zero, setting read_size to zero; then, because read_size is zero, it will set self.eos to true and look for a trailer—something it definitely shouldn’t do in the middle of an input stream.

sile commented 3 years ago

Thank you for creating this issue. Your comment sounds right. I'll fix the problem when I have time (maybe this or next weekend).

sile commented 3 years ago

Fixed in #62. Thanks again for reporting this issue.