[PATCH] D144661: Avoid unintended integer overflow in bitstream handling

Andy Kaylor via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 15 11:16:43 PDT 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7a2dfe2237ec: Avoid unintended integer overflow in bitstream handling (authored by andrew.w.kaylor).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144661/new/

https://reviews.llvm.org/D144661

Files:
  llvm/include/llvm/Bitstream/BitstreamReader.h
  llvm/include/llvm/Bitstream/BitstreamWriter.h


Index: llvm/include/llvm/Bitstream/BitstreamWriter.h
===================================================================
--- llvm/include/llvm/Bitstream/BitstreamWriter.h
+++ llvm/include/llvm/Bitstream/BitstreamWriter.h
@@ -111,7 +111,7 @@
   /// valid. Flushing only occurs at (sub)block boundaries.
   BitstreamWriter(SmallVectorImpl<char> &O, raw_fd_stream *FS = nullptr,
                   uint32_t FlushThreshold = 512)
-      : Out(O), FS(FS), FlushThreshold(FlushThreshold << 20), CurBit(0),
+      : Out(O), FS(FS), FlushThreshold(uint64_t(FlushThreshold) << 20), CurBit(0),
         CurValue(0), CurCodeSize(2) {}
 
   ~BitstreamWriter() {
Index: llvm/include/llvm/Bitstream/BitstreamReader.h
===================================================================
--- llvm/include/llvm/Bitstream/BitstreamReader.h
+++ llvm/include/llvm/Bitstream/BitstreamReader.h
@@ -115,7 +115,7 @@
 
   /// Return the bit # of the bit we are reading.
   uint64_t GetCurrentBitNo() const {
-    return NextChar*CHAR_BIT - BitsInCurWord;
+    return uint64_t(NextChar)*CHAR_BIT - BitsInCurWord;
   }
 
   // Return the byte # of the current bit.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144661.550408.patch
Type: text/x-patch
Size: 1137 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230815/5f3b16af/attachment.bin>


More information about the llvm-commits mailing list