From 7337ecf0d353d41fed2c1352833862a02f73e18f Mon Sep 17 00:00:00 2001 From: Jupiter <1040104807@qq.com> Date: Tue, 20 Jul 2021 18:21:36 +0800 Subject: [PATCH] Log when total symbol size exceeds 2^32 bytes. (#9104) * Compaction fails when total symbol size exceeds 2^32 bytes. Signed-off-by: tanghengjian <1040104807@qq.com> * Compaction fails when total symbol size exceeds 2^32 bytes. Signed-off-by: tanghengjian <1040104807@qq.com> * Compaction fails when total symbol size exceeds 2^32 bytes. Signed-off-by: root Co-authored-by: root --- tsdb/index/index.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tsdb/index/index.go b/tsdb/index/index.go index a6ade9455..3df9c36d4 100644 --- a/tsdb/index/index.go +++ b/tsdb/index/index.go @@ -523,9 +523,15 @@ func (w *Writer) AddSymbol(sym string) error { } func (w *Writer) finishSymbols() error { + symbolTableSize := w.f.pos - w.toc.Symbols - 4 + // The symbol table's part is 4 bytes. So the total symbol table size must be less than or equal to 2^32-1 + if symbolTableSize > 4294967295 { + return errors.Errorf("symbol table size exceeds 4 bytes: %d", symbolTableSize) + } + // Write out the length and symbol count. w.buf1.Reset() - w.buf1.PutBE32int(int(w.f.pos - w.toc.Symbols - 4)) + w.buf1.PutBE32int(int(symbolTableSize)) w.buf1.PutBE32int(int(w.numSymbols)) if err := w.writeAt(w.buf1.Get(), w.toc.Symbols); err != nil { return err