[llvm] [BitstreamReader] Fix 32-bit overflow in skipRecord (PR #202410)

Wei Wang via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 8 11:49:54 PDT 2026


https://github.com/apolloww created https://github.com/llvm/llvm-project/pull/202410

Follow up on 117363, which landed the fix in `readRecord`. The same fix applies to `skipRecord`.

>From 69cafdf23a54842d41bd05f74781659db120e7f1 Mon Sep 17 00:00:00 2001
From: Wei Wang <apollo.mobility at gmail.com>
Date: Mon, 8 Jun 2026 11:48:15 -0700
Subject: [PATCH] [BitstreamReader] Fix 32-bit overflow in skipRecord

---
 llvm/lib/Bitstream/Reader/BitstreamReader.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Bitstream/Reader/BitstreamReader.cpp b/llvm/lib/Bitstream/Reader/BitstreamReader.cpp
index fed9994db2ae8..c988619dc9cda 100644
--- a/llvm/lib/Bitstream/Reader/BitstreamReader.cpp
+++ b/llvm/lib/Bitstream/Reader/BitstreamReader.cpp
@@ -195,7 +195,8 @@ Expected<unsigned> BitstreamCursor::skipRecord(unsigned AbbrevID) {
     SkipToFourByteBoundary();  // 32-bit alignment
 
     // Figure out where the end of this blob will be including tail padding.
-    const size_t NewEnd = GetCurrentBitNo() + alignTo(NumElts, 4) * 8;
+    const size_t NewEnd =
+        GetCurrentBitNo() + static_cast<uint64_t>(alignTo(NumElts, 4)) * 8;
 
     // If this would read off the end of the bitcode file, just set the
     // record to empty and return.



More information about the llvm-commits mailing list