1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00

[BitcodeReader] Fix asserts when we read a non-vector type for insert/extract/shuffle

Added some additional checking for vector types + tests.

Bug found with AFL fuzz.

llvm-svn: 235710
This commit is contained in:
Filipe Cabecinhas 2015-04-24 11:30:15 +00:00
parent a0b176b76b
commit 6a560937ff
5 changed files with 18 additions and 2 deletions

View File

@ -3646,6 +3646,8 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
if (getValueTypePair(Record, OpNum, NextValueNo, Vec) || if (getValueTypePair(Record, OpNum, NextValueNo, Vec) ||
getValueTypePair(Record, OpNum, NextValueNo, Idx)) getValueTypePair(Record, OpNum, NextValueNo, Idx))
return Error("Invalid record"); return Error("Invalid record");
if (!Vec->getType()->isVectorTy())
return Error("Invalid type for value");
I = ExtractElementInst::Create(Vec, Idx); I = ExtractElementInst::Create(Vec, Idx);
InstructionList.push_back(I); InstructionList.push_back(I);
break; break;
@ -3654,8 +3656,11 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
case bitc::FUNC_CODE_INST_INSERTELT: { // INSERTELT: [ty, opval,opval,opval] case bitc::FUNC_CODE_INST_INSERTELT: { // INSERTELT: [ty, opval,opval,opval]
unsigned OpNum = 0; unsigned OpNum = 0;
Value *Vec, *Elt, *Idx; Value *Vec, *Elt, *Idx;
if (getValueTypePair(Record, OpNum, NextValueNo, Vec) || if (getValueTypePair(Record, OpNum, NextValueNo, Vec))
popValue(Record, OpNum, NextValueNo, return Error("Invalid record");
if (!Vec->getType()->isVectorTy())
return Error("Invalid type for value");
if (popValue(Record, OpNum, NextValueNo,
cast<VectorType>(Vec->getType())->getElementType(), Elt) || cast<VectorType>(Vec->getType())->getElementType(), Elt) ||
getValueTypePair(Record, OpNum, NextValueNo, Idx)) getValueTypePair(Record, OpNum, NextValueNo, Idx))
return Error("Invalid record"); return Error("Invalid record");
@ -3673,6 +3678,8 @@ std::error_code BitcodeReader::ParseFunctionBody(Function *F) {
if (getValueTypePair(Record, OpNum, NextValueNo, Mask)) if (getValueTypePair(Record, OpNum, NextValueNo, Mask))
return Error("Invalid record"); return Error("Invalid record");
if (!Vec1->getType()->isVectorTy() || !Vec2->getType()->isVectorTy())
return Error("Invalid type for value");
I = new ShuffleVectorInst(Vec1, Vec2, Mask); I = new ShuffleVectorInst(Vec1, Vec2, Mask);
InstructionList.push_back(I); InstructionList.push_back(I);
break; break;

View File

@ -78,3 +78,12 @@ RUN: not llvm-dis -disable-output %p/Inputs/invalid-array-type.bc 2>&1 | \
RUN: FileCheck --check-prefix=ARRAY-TYPE %s RUN: FileCheck --check-prefix=ARRAY-TYPE %s
ARRAY-TYPE: Array element type can't be an Array or a Blob ARRAY-TYPE: Array element type can't be an Array or a Blob
RUN: not llvm-dis -disable-output %p/Inputs/invalid-non-vector-extractelement.bc 2>&1 | \
RUN: FileCheck --check-prefix=INVALID-TYPE %s
RUN: not llvm-dis -disable-output %p/Inputs/invalid-non-vector-insertelement.bc 2>&1 | \
RUN: FileCheck --check-prefix=INVALID-TYPE %s
RUN: not llvm-dis -disable-output %p/Inputs/invalid-non-vector-shufflevector.bc 2>&1 | \
RUN: FileCheck --check-prefix=INVALID-TYPE %s
INVALID-TYPE: Invalid type for value