mirror of
https://github.com/prometheus/prometheus.git
synced 2025-08-05 21:57:09 +02:00
fix memory corruption in labels when scraping with protbuf
Signed-off-by: Piotr <17101802+thampiotr@users.noreply.github.com>
This commit is contained in:
parent
0b3ed4020c
commit
be46837c12
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
@ -40,8 +40,7 @@ jobs:
|
|||||||
- uses: prometheus/promci@443c7fc2397e946bc9f5029e313a9c3441b9b86d # v0.4.7
|
- uses: prometheus/promci@443c7fc2397e946bc9f5029e313a9c3441b9b86d # v0.4.7
|
||||||
- uses: ./.github/promci/actions/setup_environment
|
- uses: ./.github/promci/actions/setup_environment
|
||||||
- run: go test --tags=dedupelabels ./...
|
- run: go test --tags=dedupelabels ./...
|
||||||
- run: go test --tags=slicelabels -race ./cmd/prometheus
|
- run: go test --tags=slicelabels -race ./cmd/prometheus ./prompb/io/prometheus/client
|
||||||
- run: go test --tags=slicelabels -race ./prompb/io/prometheus/client
|
|
||||||
- run: go test --tags=forcedirectio -race ./tsdb/
|
- run: go test --tags=forcedirectio -race ./tsdb/
|
||||||
- run: GOARCH=386 go test ./...
|
- run: GOARCH=386 go test ./...
|
||||||
- uses: ./.github/promci/actions/check_proto
|
- uses: ./.github/promci/actions/check_proto
|
||||||
|
@ -62,6 +62,9 @@ func NewMetricStreamingDecoder(data []byte) *MetricStreamingDecoder {
|
|||||||
|
|
||||||
var errInvalidVarint = errors.New("clientpb: invalid varint encountered")
|
var errInvalidVarint = errors.New("clientpb: invalid varint encountered")
|
||||||
|
|
||||||
|
// NextMetricFamily decodes the next metric family from the input without metrics.
|
||||||
|
// Use NextMetric() to decode metrics. The MetricFamily fields Name, Help and Unit
|
||||||
|
// are only valid until NextMetricFamily is called again.
|
||||||
func (m *MetricStreamingDecoder) NextMetricFamily() error {
|
func (m *MetricStreamingDecoder) NextMetricFamily() error {
|
||||||
b := m.in[m.inPos:]
|
b := m.in[m.inPos:]
|
||||||
if len(b) == 0 {
|
if len(b) == 0 {
|
||||||
@ -153,6 +156,7 @@ func (m *MetricStreamingDecoder) GetLabel() {
|
|||||||
|
|
||||||
type scratchBuilder interface {
|
type scratchBuilder interface {
|
||||||
Add(name, value string)
|
Add(name, value string)
|
||||||
|
UnsafeAddBytes(name, value []byte)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Label parses labels into labels scratch builder. Metric name is missing
|
// Label parses labels into labels scratch builder. Metric name is missing
|
||||||
@ -170,9 +174,9 @@ func (m *MetricStreamingDecoder) Label(b scratchBuilder) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// parseLabel is essentially LabelPair.Unmarshal but directly adding into scratch builder
|
// parseLabel is essentially LabelPair.Unmarshal but directly adding into scratch builder
|
||||||
// and reusing strings.
|
// via UnsafeAddBytes method to reuse strings.
|
||||||
func parseLabel(dAtA []byte, b scratchBuilder) error {
|
func parseLabel(dAtA []byte, b scratchBuilder) error {
|
||||||
var name, value string
|
var name, value []byte
|
||||||
l := len(dAtA)
|
l := len(dAtA)
|
||||||
iNdEx := 0
|
iNdEx := 0
|
||||||
for iNdEx < l {
|
for iNdEx < l {
|
||||||
@ -231,7 +235,7 @@ func parseLabel(dAtA []byte, b scratchBuilder) error {
|
|||||||
if postIndex > l {
|
if postIndex > l {
|
||||||
return io.ErrUnexpectedEOF
|
return io.ErrUnexpectedEOF
|
||||||
}
|
}
|
||||||
name = yoloString(dAtA[iNdEx:postIndex])
|
name = dAtA[iNdEx:postIndex]
|
||||||
if !model.LabelName(name).IsValid() {
|
if !model.LabelName(name).IsValid() {
|
||||||
return fmt.Errorf("invalid label name: %s", name)
|
return fmt.Errorf("invalid label name: %s", name)
|
||||||
}
|
}
|
||||||
@ -266,8 +270,8 @@ func parseLabel(dAtA []byte, b scratchBuilder) error {
|
|||||||
if postIndex > l {
|
if postIndex > l {
|
||||||
return io.ErrUnexpectedEOF
|
return io.ErrUnexpectedEOF
|
||||||
}
|
}
|
||||||
value = yoloString(dAtA[iNdEx:postIndex])
|
value = dAtA[iNdEx:postIndex]
|
||||||
if !utf8.ValidString(value) {
|
if !utf8.ValidString(yoloString(value)) {
|
||||||
return fmt.Errorf("invalid label value: %s", value)
|
return fmt.Errorf("invalid label value: %s", value)
|
||||||
}
|
}
|
||||||
iNdEx = postIndex
|
iNdEx = postIndex
|
||||||
@ -289,7 +293,7 @@ func parseLabel(dAtA []byte, b scratchBuilder) error {
|
|||||||
if iNdEx > l {
|
if iNdEx > l {
|
||||||
return io.ErrUnexpectedEOF
|
return io.ErrUnexpectedEOF
|
||||||
}
|
}
|
||||||
b.Add(name, value)
|
b.UnsafeAddBytes(name, value)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user