[PATCH] D47731: Fix for llvm-dis/llvm-bcanalyzer overflows

Teresa Johnson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 4 10:56:11 PDT 2018


tejohnson created this revision.
tejohnson added a reviewer: pcc.
Herald added subscribers: a.sidorin, mehdi_amini.
Herald added a reviewer: george.karpenkov.

These tools failed for a very large bitcode file produced by LTO due to
64-bit values being assigned to 32-bit types. For the BitstreamReader.h
fix, the value initially fit into the 32-bit unsigned, but there was an
overflow when multiplying by 32 furter below to compute the bit offset.

No test case in the patch as this requires a huge bitcode file.


Repository:
  rL LLVM

https://reviews.llvm.org/D47731

Files:
  include/llvm/Bitcode/BitstreamReader.h
  tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp


Index: tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
===================================================================
--- tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
+++ tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
@@ -602,7 +602,7 @@
     ++BlockStats.NumRecords;
 
     StringRef Blob;
-    unsigned CurrentRecordPos = Stream.GetCurrentBitNo();
+    uint64_t CurrentRecordPos = Stream.GetCurrentBitNo();
     unsigned Code = Stream.readRecord(Entry.ID, Record, &Blob);
 
     // Increment the # occurrences of this code.
Index: include/llvm/Bitcode/BitstreamReader.h
===================================================================
--- include/llvm/Bitcode/BitstreamReader.h
+++ include/llvm/Bitcode/BitstreamReader.h
@@ -429,7 +429,7 @@
     // don't care what code widths are used inside of it.
     ReadVBR(bitc::CodeLenWidth);
     SkipToFourByteBoundary();
-    unsigned NumFourBytes = Read(bitc::BlockSizeWidth);
+    size_t NumFourBytes = Read(bitc::BlockSizeWidth);
 
     // Check that the block wasn't partially defined, and that the offset isn't
     // bogus.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47731.149806.patch
Type: text/x-patch
Size: 1071 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180604/db2603b9/attachment.bin>


More information about the llvm-commits mailing list