fix(model/textparse): Labels(): copy the input to avoid dangling references

Signed-off-by: machine424 <ayoubmrini424@gmail.com>
This commit is contained in:
machine424 2025-05-23 11:03:48 +02:00
parent 2bfbd8a714
commit 50a6efd5ec
No known key found for this signature in database
GPG key ID: A4B001A4FDEE017D
2 changed files with 6 additions and 2 deletions

View file

@ -213,7 +213,9 @@ func (p *OpenMetricsParser) Comment() []byte {
// Labels writes the labels of the current sample into the passed labels. // Labels writes the labels of the current sample into the passed labels.
func (p *OpenMetricsParser) Labels(l *labels.Labels) { func (p *OpenMetricsParser) Labels(l *labels.Labels) {
s := yoloString(p.series) // Defensive copy in case the following keeps a reference.
// See https://github.com/prometheus/prometheus/issues/16490
s := string(p.series)
p.builder.Reset() p.builder.Reset()
metricName := unreplace(s[p.offsets[0]-p.start : p.offsets[1]-p.start]) metricName := unreplace(s[p.offsets[0]-p.start : p.offsets[1]-p.start])

View file

@ -229,7 +229,9 @@ func (p *PromParser) Comment() []byte {
// Labels writes the labels of the current sample into the passed labels. // Labels writes the labels of the current sample into the passed labels.
func (p *PromParser) Labels(l *labels.Labels) { func (p *PromParser) Labels(l *labels.Labels) {
s := yoloString(p.series) // Defensive copy in case the following keeps a reference.
// See https://github.com/prometheus/prometheus/issues/16490
s := string(p.series)
p.builder.Reset() p.builder.Reset()
metricName := unreplace(s[p.offsets[0]-p.start : p.offsets[1]-p.start]) metricName := unreplace(s[p.offsets[0]-p.start : p.offsets[1]-p.start])