Skip to content

Commit

Permalink
return directly when messageSize is too small
Browse files Browse the repository at this point in the history
  • Loading branch information
childe committed Oct 15, 2024
1 parent 89ffa1c commit c9310ad
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion fetch_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,22 @@ func (streamDecoder *fetchResponseStreamDecoder) decodeMessageSetMagic0or1(topic
for {
if firstMessageSet {
firstMessageSet = false

// messageSize doesn't include the size of messageSize itself.
messageSize := int(binary.BigEndian.Uint32(header17[8:]))
value = make([]byte, 12+messageSize) // messageSize doesn't include the size of messageSize itself. 12 equals to the size of the header of offset & message_size.
if messageSize < 6 {
return
}

// 12 is the size of offset(int64) & message_size(int32) in header17
value = make([]byte, 12+messageSize)
copy(value, header17)
n, e := streamDecoder.Read(value[17:])
if e != nil {
return offset, e
}

// remaining bytes is not complete
if n < messageSize-17 {
return
}
Expand Down

0 comments on commit c9310ad

Please sign in to comment.