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 <tanghengjian@oppo.com>

Co-authored-by: root <tanghengjian@oppo.com>
This commit is contained in:
Jupiter 2021-07-20 18:21:36 +08:00 committed by GitHub
parent 59d02b5ef0
commit 7337ecf0d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -523,9 +523,15 @@ func (w *Writer) AddSymbol(sym string) error {
} }
func (w *Writer) finishSymbols() error { func (w *Writer) finishSymbols() error {
symbolTableSize := w.f.pos - w.toc.Symbols - 4
// The symbol table's <len> 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. // Write out the length and symbol count.
w.buf1.Reset() 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)) w.buf1.PutBE32int(int(w.numSymbols))
if err := w.writeAt(w.buf1.Get(), w.toc.Symbols); err != nil { if err := w.writeAt(w.buf1.Get(), w.toc.Symbols); err != nil {
return err return err