Skip to content

Commit

Permalink
Fix an infinite loop in flush
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Jan 18, 2017
1 parent 6fac4f7 commit d98941c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/gz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,4 +664,11 @@ mod tests {
v == v2
}
}

#[test]
fn flush_after_write() {
let mut f = EncoderWriter::new(Vec::new(), Default);
write!(f, "Hello world").unwrap();
f.flush().unwrap();
}
}
5 changes: 3 additions & 2 deletions src/zio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,17 @@ impl<W: Write, D: Ops> Write for Writer<W, D> {
}

fn flush(&mut self) -> io::Result<()> {
self.data.run_vec(&[], &mut self.buf, Flush::Sync).unwrap();

// Unfortunately miniz doesn't actually tell us when we're done with
// pulling out all the data from the internal stream. To remedy this we
// have to continually ask the stream for more memory until it doesn't
// give us a chunk of memory the same size as our own internal buffer,
// at which point we assume it's reached the end.
loop {
try!(self.dump());

let before = self.data.total_out();
self.data.run_vec(&[], &mut self.buf, Flush::Sync).unwrap();
self.data.run_vec(&[], &mut self.buf, Flush::None).unwrap();
if before == self.data.total_out() {
break
}
Expand Down

0 comments on commit d98941c

Please sign in to comment.