From bad0779f6310af38570f4fcfc68ea876d5e4dca7 Mon Sep 17 00:00:00 2001 From: Filipe Cabecinhas Date: Thu, 30 Apr 2015 00:52:42 +0000 Subject: [PATCH] Make sure we don't resize(0) when we get a fwdref with Idx == UINT_MAX Make it an error instead. Bug found with AFL fuzz. llvm-svn: 236190 --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 4 ++++ llvm/test/Bitcode/Inputs/invalid-too-big-fwdref.bc | Bin 0 -> 452 bytes llvm/test/Bitcode/invalid.test | 5 +++++ 3 files changed, 9 insertions(+) create mode 100644 llvm/test/Bitcode/Inputs/invalid-too-big-fwdref.bc diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index f49a538..7778125 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -790,6 +790,10 @@ Constant *BitcodeReaderValueList::getConstantFwdRef(unsigned Idx, } Value *BitcodeReaderValueList::getValueFwdRef(unsigned Idx, Type *Ty) { + // Bail out for a clearly invalid value. This would make us call resize(0) + if (Idx == UINT_MAX) + return nullptr; + if (Idx >= size()) resize(Idx + 1); diff --git a/llvm/test/Bitcode/Inputs/invalid-too-big-fwdref.bc b/llvm/test/Bitcode/Inputs/invalid-too-big-fwdref.bc new file mode 100644 index 0000000000000000000000000000000000000000..d1d51a634fc286ae62c112690d72237dac66e3b5 GIT binary patch literal 452 zcmZ>AK5$Qwhk+rFfq{X$Nr8b0NDBcmd!zD1#}h1`Yyw7>lNeigR9QJB}F$U~Vl5k}h%XN#7@Jx&eml@;v8GYWa0 zG4Q_?;QP|RXUyXycj%z(xrH)m2CQIZ&C+L>ZBIDc_AuK5%_vl0U;vpXwn3rS#U+?k zM9&`6j5d{ oF$U6`1)CrK-z<0t=vh9HuR-oYm@Nu4>1rC#q!frrKuI6~0H$zcNdN!< literal 0 HcmV?d00001 diff --git a/llvm/test/Bitcode/invalid.test b/llvm/test/Bitcode/invalid.test index c18ff3d..077f351 100644 --- a/llvm/test/Bitcode/invalid.test +++ b/llvm/test/Bitcode/invalid.test @@ -112,3 +112,8 @@ RUN: not llvm-dis -disable-output %p/Inputs/invalid-array-op-not-2nd-to-last.bc RUN: FileCheck --check-prefix=ARRAY-NOT-2LAST %s ARRAY-NOT-2LAST: Array op not second to last + +RUN: not llvm-dis -disable-output %p/Inputs/invalid-too-big-fwdref.bc 2>&1 | \ +RUN: FileCheck --check-prefix=HUGE-FWDREF %s + +HUGE-FWDREF: Invalid record -- 2.7.4