prometheus/model/histogram
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
..
convert.go fix(histogram): handling +Inf bucket count and metric label 2025-10-28 20:29:44 +05:30
convert_test.go fix(histogram): handling +Inf bucket count and metric label 2025-10-28 20:29:44 +05:30
float_histogram.go perf(PromQL): improve performance of FloatHistogram.KahanAdd 2026-03-06 17:50:55 +02:00
float_histogram_test.go histograms: BenchmarkFloatHistogramAdd (#18248) 2026-03-17 15:07:56 +01:00
generic.go histogram, textparse: fix two panics in compactBuckets for malformed input 2026-03-31 17:37:09 +02:00
generic_test.go Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00
histogram.go promql: use Kahan summation for Native Histograms (#15687) 2026-02-08 00:52:22 +01:00
histogram_test.go histogram, textparse: fix two panics in compactBuckets for malformed input 2026-03-31 17:37:09 +02:00
test_utils.go Remove copyright date from headers (#17785) 2026-01-05 13:46:21 +01:00