diff options
author | Eli Friedman <efriedma@quicinc.com> | 2020-05-16 14:01:54 -0700 |
---|---|---|
committer | Eli Friedman <efriedma@quicinc.com> | 2020-05-16 14:24:51 -0700 |
commit | 0ec5f501964010d4a186a51438338656eebe7912 (patch) | |
tree | ae51c030a04ae561279f93496cbdb81a388dd43e /llvm/lib/Bitcode/Reader/BitcodeReader.cpp | |
parent | accd9af838b071ff6e8ba4ff3c99a2542cd0ce25 (diff) | |
download | llvm-0ec5f501964010d4a186a51438338656eebe7912.zip llvm-0ec5f501964010d4a186a51438338656eebe7912.tar.gz llvm-0ec5f501964010d4a186a51438338656eebe7912.tar.bz2 |
Harden IR and bitcode parsers against infinite size types.
If isSized is passed a SmallPtrSet, it uses that set to catch infinitely
recursive types (for example, a struct that has itself as a member).
Otherwise, it just crashes on such types.
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 64427b7..7b62bab 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -4857,7 +4857,8 @@ Error BitcodeReader::parseFunctionBody(Function *F) { MaybeAlign Align; if (Error Err = parseAlignmentValue(Record[OpNum], Align)) return Err; - if (!Align && !Ty->isSized()) + SmallPtrSet<Type *, 4> Visited; + if (!Align && !Ty->isSized(&Visited)) return error("load of unsized type"); if (!Align) Align = TheModule->getDataLayout().getABITypeAlign(Ty); @@ -4922,6 +4923,9 @@ Error BitcodeReader::parseFunctionBody(Function *F) { MaybeAlign Align; if (Error Err = parseAlignmentValue(Record[OpNum], Align)) return Err; + SmallPtrSet<Type *, 4> Visited; + if (!Align && !Val->getType()->isSized(&Visited)) + return error("store of unsized type"); if (!Align) Align = TheModule->getDataLayout().getABITypeAlign(Val->getType()); I = new StoreInst(Val, Ptr, Record[OpNum + 1], *Align); |