Skip to content

Commit

Permalink
Fix edge condition with kafka request parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
grcevski committed Oct 11, 2024
1 parent bc125f7 commit 420bdb3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/internal/ebpf/common/kafka_detect_transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func getTopicNameSize(pkt []byte, offset int, op Operation, apiVersion int16) (i
if err != nil {
return 0, err
}
} else if offset < len(pkt) {
} else if offset < (len(pkt) - 1) { // we need at least 2 bytes to read uint16
topicNameSize = int(binary.BigEndian.Uint16(pkt[offset:]))
}
if topicNameSize <= 0 {
Expand Down
9 changes: 9 additions & 0 deletions pkg/internal/ebpf/common/kafka_detect_transform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ func TestProcessKafkaRequest(t *testing.T) {
input []byte
expected *KafkaInfo
}{
{
name: "Fetch request (v11) truncated - 1",
input: []byte{0, 0, 0, 94, 0, 1, 0, 11, 0, 0, 0, 224, 0, 6, 115, 97, 114, 97, 109, 97, 255, 255, 255, 255, 0, 0, 1, 244, 0, 0, 0, 1, 6, 64, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 1, 0},
expected: &KafkaInfo{
ClientID: "sarama",
Operation: Fetch,
TopicOffset: 45,
},
},
{
name: "Fetch request (v11) truncated",
input: []byte{0, 0, 0, 94, 0, 1, 0, 11, 0, 0, 0, 224, 0, 6, 115, 97, 114, 97, 109, 97, 255, 255, 255, 255, 0, 0, 1, 244, 0, 0, 0, 1, 6, 64, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 1},
Expand Down

0 comments on commit 420bdb3

Please sign in to comment.