diff --git a/index/index.go b/index/index.go index 6b333fa58..c18f77d16 100644 --- a/index/index.go +++ b/index/index.go @@ -781,9 +781,13 @@ func ReadOffsetTable(bs ByteSlice, off uint64, f func([]string, uint64) error) e d := encoding.NewDecbufAt(bs, int(off), castagnoliTable) cnt := d.Be32() + // The Postings offset table takes only 2 keys per entry (name and value of label), + // and the LabelIndices offset table takes only 1 key per entry (a label name). + // Hence setting the size to max of both, i.e. 2. + keys := make([]string, 0, 2) for d.Err() == nil && d.Len() > 0 && cnt > 0 { keyCount := d.Uvarint() - keys := make([]string, 0, keyCount) + keys = keys[:0] for i := 0; i < keyCount; i++ { keys = append(keys, d.UvarintStr())