[llvm] 8df6321 - [BitstreamReader] Fix 32-bit overflow (#117363)

via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 27 14:53:37 PST 2024


Author: Pranav Kant
Date: 2024-11-27T14:53:34-08:00
New Revision: 8df63211a65693c7cc760e361adf20edd450fafa

URL: https://github.com/llvm/llvm-project/commit/8df63211a65693c7cc760e361adf20edd450fafa
DIFF: https://github.com/llvm/llvm-project/commit/8df63211a65693c7cc760e361adf20edd450fafa.diff

LOG: [BitstreamReader] Fix 32-bit overflow  (#117363)

This got exposed when processing large LTO-generated files leading to
crashes.

Added: 
    

Modified: 
    llvm/lib/Bitstream/Reader/BitstreamReader.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Bitstream/Reader/BitstreamReader.cpp b/llvm/lib/Bitstream/Reader/BitstreamReader.cpp
index 5b2c76350029be..fed9994db2ae85 100644
--- a/llvm/lib/Bitstream/Reader/BitstreamReader.cpp
+++ b/llvm/lib/Bitstream/Reader/BitstreamReader.cpp
@@ -334,7 +334,8 @@ Expected<unsigned> BitstreamCursor::readRecord(unsigned AbbrevID,
 
     // Figure out where the end of this blob will be including tail padding.
     size_t CurBitPos = GetCurrentBitNo();
-    const size_t NewEnd = CurBitPos + alignTo(NumElts, 4) * 8;
+    const size_t NewEnd =
+        CurBitPos + static_cast<uint64_t>(alignTo(NumElts, 4)) * 8;
 
     // Make sure the bitstream is large enough to contain the blob.
     if (!canSkipToPos(NewEnd/8))


        


More information about the llvm-commits mailing list