opentelemetry: fix firehose message parsing (#5899)

Co-authored-by: Andrii Chubatiuk <wachy@Andriis-MBP-2.lan>
This commit is contained in:
Andrii Chubatiuk 2024-03-01 00:23:54 +02:00 committed by Aliaksandr Valialkin
parent 728fb59e0d
commit e575fb1aeb
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB
2 changed files with 34 additions and 7 deletions

View file

@ -1,6 +1,7 @@
package firehose package firehose
import ( import (
"encoding/binary"
"encoding/json" "encoding/json"
"fmt" "fmt"
) )
@ -32,8 +33,18 @@ func ProcessRequestBody(b []byte) ([]byte, error) {
var dst []byte var dst []byte
for _, r := range req.Records { for _, r := range req.Records {
dst = append(dst, r.Data...) for len(r.Data) > 0 {
messageLength, varIntLength := binary.Uvarint(r.Data)
if varIntLength > binary.MaxVarintLen32 {
return nil, fmt.Errorf("failed to parse OpenTelemetry message: invalid variant")
}
totalLength := varIntLength + int(messageLength)
if totalLength > len(r.Data) {
return nil, fmt.Errorf("failed to parse OpenTelementry message: insufficient length of buffer")
}
dst = append(dst, r.Data[varIntLength:totalLength]...)
r.Data = r.Data[totalLength:]
}
} }
return dst, nil return dst, nil
} }

File diff suppressed because one or more lines are too long