prometheus/model/textparse
Julien Pivotto c9dd34ac6b histogram, textparse: fix two panics in compactBuckets for malformed input
Two cases in compactBuckets caused a panic when fed malformed histogram
data (e.g. via a crafted protobuf message):

1. All spans have zero length: after the zero-length span removal pass,
   spans becomes empty. The subsequent loop called emptyBucketsHere(),
   which accessed spans[0] and panicked with index out of range.
   Fixed by the early return added in the previous commit (already on
   this branch via the roidelapluie/histogram-compact-zero-spans fix).

2. More buckets than spans describe: iSpan can reach len(spans) before
   all buckets are consumed, causing emptyBucketsHere() to access
   spans[iSpan] out of bounds.
   Fixed by adding iSpan < len(spans) to the loop guard.

Both fixes in compactBuckets are defensive layers. The primary fix is
in the protobuf parser: checkNativeHistogramConsistency now validates
that span total length matches bucket count before calling Compact(),
returning a proper error for malformed input instead of panicking.

Found by FuzzParseProtobuf.

Signed-off-by: Julien Pivotto <291750+roidelapluie@users.noreply.github.com>
2026-03-31 17:37:09 +02:00
..
testdata textparse: Refactor benchmark testdata for all types. (#15998) 2025-02-10 12:26:18 +00:00
benchmark_test.go Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
interface.go Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
interface_test.go Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
nhcbparse.go Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
nhcbparse_test.go Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
openmetricslex.l bugfix: allow quoted exemplar keys in openmetrics text format 2024-11-12 15:29:44 +00:00
openmetricslex.l.go Update golangci-lint (#17478) 2025-11-05 13:47:34 +01:00
openmetricsparse.go textparse: fix parseLVals to only treat quoted strings as metric names 2026-03-05 15:07:42 +01:00
openmetricsparse_test.go textparse: fix parseLVals to only treat quoted strings as metric names 2026-03-05 15:07:42 +01:00
promlex.l UTF-8: Add support for parsing UTF8 metric and label names 2024-02-15 14:34:37 -05:00
promlex.l.go Update golangci-lint (#17478) 2025-11-05 13:47:34 +01:00
promparse.go textparse: fix parseLVals to only treat quoted strings as metric names 2026-03-05 15:07:42 +01:00
promparse_test.go textparse: fix parseLVals to only treat quoted strings as metric names 2026-03-05 15:07:42 +01:00
protobufparse.go histogram, textparse: fix two panics in compactBuckets for malformed input 2026-03-31 17:37:09 +02:00
protobufparse_test.go histogram, textparse: fix two panics in compactBuckets for malformed input 2026-03-31 17:37:09 +02:00
README.md Move packages out of deprecated pkg directory 2021-11-09 08:03:10 +01:00

Making changes to textparse lexers

In the rare case that you need to update the textparse lexers, edit promlex.l or openmetricslex.l and then run the following command: golex -o=promlex.l.go promlex.l

Note that you need golex installed: go get -u modernc.org/golex