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 GitHub
parent fdf0cc9f25
commit bf9cb84575
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 7 deletions

View file

@ -1,6 +1,7 @@
package firehose
import (
"encoding/binary"
"encoding/json"
"fmt"
)
@ -32,8 +33,18 @@ func ProcessRequestBody(b []byte) ([]byte, error) {
var dst []byte
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
}

File diff suppressed because one or more lines are too long