[ELF] --gdb-index: error if constant pool size exceeds UINT32_MAX

If so, the last symbol's name_offset likely exceeds 0xffffffff and is not
supported by the format
(https://sourceware.org/gdb/onlinedocs/gdb/Index-Section-Format.html#Index-Section-Format).
I have seen an internal oversized executable with such a corrupted .gdb_index
This commit is contained in:
Fangrui Song 2022-08-31 21:10:01 -07:00
parent 7a20d6abe4
commit 5e643cd7b7
1 changed files with 4 additions and 0 deletions

View File

@ -2844,6 +2844,10 @@ createSymbols(
sym.nameOff = off;
off += sym.name.size() + 1;
}
// If off overflows, the last symbol's nameOff likely overflows.
if (!isUInt<32>(off))
errorOrWarn("--gdb-index: constant pool size (" + Twine(off) +
") exceeds UINT32_MAX");
return {ret, off};
}