Skip to content

Commit eec120a

Browse files
fixup! Ensure that decompressBuffer doesn't get reallocated by io.CopyN
1 parent c926904 commit eec120a

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

parquet/file/page_reader.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,11 +509,10 @@ func (p *serializedPageReader) decompress(rd io.Reader, lenCompressed int, buf [
509509
// However, bytes.Buffer always attempts to read at least bytes.MinRead (which is 512 bytes) from the
510510
// underlying reader, even if there is less data available than that. So even if there are no more bytes,
511511
// the buffer must have at least bytes.MinRead capacity remaining to avoid a relocation.
512-
allocSize := lenCompressed
513512
if p.decompressBuffer.Cap() < lenCompressed+bytes.MinRead {
514-
allocSize = lenCompressed + bytes.MinRead
513+
p.decompressBuffer.Reserve(lenCompressed + bytes.MinRead)
515514
}
516-
p.decompressBuffer.ResizeNoShrink(allocSize)
515+
p.decompressBuffer.ResizeNoShrink(lenCompressed)
517516
b := bytes.NewBuffer(p.decompressBuffer.Bytes()[:0])
518517
if _, err := io.CopyN(b, rd, int64(lenCompressed)); err != nil {
519518
return nil, err

0 commit comments

Comments
 (0)