Skip to content

Commit

Permalink
More aggressive resets of state in xerial reader (segmentio#322)
Browse files Browse the repository at this point in the history
In cases where the xerial reader requires more bytes than available
in the decompressed buffer, we currently get corrupt data.  That
would result in the reader halting.  Clearing out x.output and
x.header ensures that this condition is handled gracefully.
  • Loading branch information
Steve van Loben Sels authored Jul 23, 2019
1 parent c98551b commit 1248320
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions snappy/xerial.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func (x *xerialReader) Reset(r io.Reader) {
x.reader = r
x.input = x.input[:0]
x.output = x.output[:0]
x.header = [16]byte{}
x.offset = 0
x.nbytes = 0
}
Expand Down Expand Up @@ -72,6 +73,7 @@ func (x *xerialReader) WriteTo(w io.Writer) (int64, error) {
}

func (x *xerialReader) readChunk(dst []byte) (int, error) {
x.output = x.output[:0]
x.offset = 0
prefix := 0

Expand Down

0 comments on commit 1248320

Please sign in to comment.