From 0c553bff8e76ebfbf9cd4e94ff565018ed1ff0c1 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 7 Feb 2022 11:51:19 +0100 Subject: [Bitcode] Guard against out of bounds value reference We should make sure that the value ID is in bounds, otherwise we will assert / read out of bounds. --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 308986a..c24dcf0 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2107,11 +2107,15 @@ Error BitcodeReader::parseGlobalValueSymbolTable() { if (!MaybeRecord) return MaybeRecord.takeError(); switch (MaybeRecord.get()) { - case bitc::VST_CODE_FNENTRY: // [valueid, offset] + case bitc::VST_CODE_FNENTRY: { // [valueid, offset] + unsigned ValueID = Record[0]; + if (ValueID >= ValueList.size() || !ValueList[ValueID]) + return error("Invalid value reference in symbol table"); setDeferredFunctionInfo(FuncBitcodeOffsetDelta, - cast(ValueList[Record[0]]), Record); + cast(ValueList[ValueID]), Record); break; } + } } } -- cgit v1.1