Fix infinite loop in index Writer when a series contains duplicated label names
Signed-off-by: Marco Pracucci <marco@pracucci.com>
This commit is contained in:
parent
031d22df9e
commit
35069910f5
|
@ -864,8 +864,11 @@ func (w *Writer) writePostingsToTmpFiles() error {
|
|||
// using more memory than a single label name can.
|
||||
for len(names) > 0 {
|
||||
if w.labelNames[names[0]]+c > maxPostings {
|
||||
if c > 0 {
|
||||
break
|
||||
}
|
||||
return fmt.Errorf("corruption detected when writing postings to index: label %q has %d uses, but maxPostings is %d", names[0], w.labelNames[names[0]], maxPostings)
|
||||
}
|
||||
batchNames = append(batchNames, names[0])
|
||||
c += w.labelNames[names[0]]
|
||||
names = names[1:]
|
||||
|
|
|
@ -471,6 +471,21 @@ func TestPersistence_index_e2e(t *testing.T) {
|
|||
require.NoError(t, ir.Close())
|
||||
}
|
||||
|
||||
func TestWriter_ShouldReturnErrorOnSeriesWithDuplicatedLabelNames(t *testing.T) {
|
||||
w, err := NewWriter(context.Background(), filepath.Join(t.TempDir(), "index"))
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NoError(t, w.AddSymbol("__name__"))
|
||||
require.NoError(t, w.AddSymbol("metric_1"))
|
||||
require.NoError(t, w.AddSymbol("metric_2"))
|
||||
|
||||
require.NoError(t, w.AddSeries(0, labels.FromStrings("__name__", "metric_1", "__name__", "metric_2")))
|
||||
|
||||
err = w.Close()
|
||||
require.Error(t, err)
|
||||
require.ErrorContains(t, err, "corruption detected when writing postings to index")
|
||||
}
|
||||
|
||||
func TestDecbufUvarintWithInvalidBuffer(t *testing.T) {
|
||||
b := realByteSlice([]byte{0x81, 0x81, 0x81, 0x81, 0x81, 0x81})
|
||||
|
||||
|
|
Loading…
Reference in New Issue