[llvm] r234984 - Verify sizes when trying to read a VBR

Filipe Cabecinhas me at filcab.net
Wed Apr 15 01:48:08 PDT 2015


Author: filcab
Date: Wed Apr 15 03:48:08 2015
New Revision: 234984

URL: http://llvm.org/viewvc/llvm-project?rev=234984&view=rev
Log:
Verify sizes when trying to read a VBR

Also added an assert to ReadVBR64.

Added:
    llvm/trunk/test/Bitcode/Inputs/invalid-VBR-too-big.bc
Modified:
    llvm/trunk/include/llvm/Bitcode/BitstreamReader.h
    llvm/trunk/lib/Bitcode/Reader/BitstreamReader.cpp
    llvm/trunk/test/Bitcode/invalid.test

Modified: llvm/trunk/include/llvm/Bitcode/BitstreamReader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/BitstreamReader.h?rev=234984&r1=234983&r2=234984&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Bitcode/BitstreamReader.h (original)
+++ llvm/trunk/include/llvm/Bitcode/BitstreamReader.h Wed Apr 15 03:48:08 2015
@@ -395,6 +395,7 @@ public:
   // Read a VBR that may have a value up to 64-bits in size. The chunk size of
   // the VBR must still be <= 32 bits though.
   uint64_t ReadVBR64(unsigned NumBits) {
+    assert(NumBits <= 64 && "VBR can only be up to 64 bits in size.");
     uint32_t Piece = Read(NumBits);
     if ((Piece & (1U << (NumBits-1))) == 0)
       return uint64_t(Piece);

Modified: llvm/trunk/lib/Bitcode/Reader/BitstreamReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitstreamReader.cpp?rev=234984&r1=234983&r2=234984&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitstreamReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitstreamReader.cpp Wed Apr 15 03:48:08 2015
@@ -62,6 +62,8 @@ static uint64_t readAbbreviatedField(Bit
   case BitCodeAbbrevOp::Fixed:
     return Cursor.Read((unsigned)Op.getEncodingData());
   case BitCodeAbbrevOp::VBR:
+    if ((unsigned)Op.getEncodingData() > 64)
+      report_fatal_error("Invalid record");
     return Cursor.ReadVBR64((unsigned)Op.getEncodingData());
   case BitCodeAbbrevOp::Char6:
     return BitCodeAbbrevOp::DecodeChar6(Cursor.Read(6));

Added: llvm/trunk/test/Bitcode/Inputs/invalid-VBR-too-big.bc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/Inputs/invalid-VBR-too-big.bc?rev=234984&view=auto
==============================================================================
Binary files llvm/trunk/test/Bitcode/Inputs/invalid-VBR-too-big.bc (added) and llvm/trunk/test/Bitcode/Inputs/invalid-VBR-too-big.bc Wed Apr 15 03:48:08 2015 differ

Modified: llvm/trunk/test/Bitcode/invalid.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/invalid.test?rev=234984&r1=234983&r2=234984&view=diff
==============================================================================
--- llvm/trunk/test/Bitcode/invalid.test (original)
+++ llvm/trunk/test/Bitcode/invalid.test Wed Apr 15 03:48:08 2015
@@ -55,3 +55,8 @@ RUN: not llvm-dis -disable-output %p/Inp
 RUN:   FileCheck --check-prefix=NO-MODULE %s
 
 NO-MODULE: Malformed IR file
+
+RUN: not llvm-dis -disable-output %p/Inputs/invalid-VBR-too-big.bc 2>&1 | \
+RUN:   FileCheck --check-prefix=HUGE-VBR %s
+
+HUGE-VBR: Invalid record





More information about the llvm-commits mailing list