Skip to content

Commit

Permalink
fix: don't assume the header count will be positive (segmentio#882)
Browse files Browse the repository at this point in the history
  • Loading branch information
Achille authored Apr 11, 2022
1 parent 4296f73 commit 94daae2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions message_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,12 @@ func (r *messageSetReader) readMessageV2(_ int64, key readBytesFunc, val readByt
if err = r.readVarInt(&headerCount); err != nil {
return
}
headers = make([]Header, headerCount)
for i := 0; i < int(headerCount); i++ {
if err = r.readMessageHeader(&headers[i]); err != nil {
return
if headerCount > 0 {
headers = make([]Header, headerCount)
for i := range headers {
if err = r.readMessageHeader(&headers[i]); err != nil {
return
}
}
}
lastOffset = r.header.firstOffset + int64(r.header.v2.lastOffsetDelta)
Expand Down

0 comments on commit 94daae2

Please sign in to comment.