[llvm] [MC] Prevent multiplication overflow when calling `encodeULEB128` (PR #224647)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 23 05:53:29 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-debuginfo

Author: Igor Wodiany (IgWod)

<details>
<summary>Changes</summary>

`encodeULEB128` takes its `Value` as a 64-bit integer but the multiplication is done using 32 bits. This fixes two issues reported by a CodeQL scan however it's unclear how realistic an overflow is in this case, as I'm not sure what are the max expected sizes for `Lane` and `SizeInBits` under normal circumstances -- happy to abandon the PR if the fix is not actually needed.

---
Full diff: https://github.com/llvm/llvm-project/pull/224647.diff


1 Files Affected:

- (modified) llvm/lib/MC/MCDwarf.cpp (+3-2) 


``````````diff
diff --git a/llvm/lib/MC/MCDwarf.cpp b/llvm/lib/MC/MCDwarf.cpp
index b06ab36d1d66d4..c0df9700dea7a9 100644
--- a/llvm/lib/MC/MCDwarf.cpp
+++ b/llvm/lib/MC/MCDwarf.cpp
@@ -1697,7 +1697,8 @@ void FrameEmitterImpl::emitCFIInstruction(const MCCFIInstruction &Instr) {
       encodeDwarfRegisterLocation(VRs[0].Register, OSBlock);
       OSBlock << uint8_t(dwarf::DW_OP_LLVM_user)
               << uint8_t(dwarf::DW_OP_LLVM_offset_uconst);
-      encodeULEB128((VRs[0].SizeInBits / 8) * VRs[0].Lane, OSBlock);
+      encodeULEB128(static_cast<uint64_t>(VRs[0].SizeInBits / 8) * VRs[0].Lane,
+                    OSBlock);
     } else {
       for (const auto &VR : VRs) {
         // TODO: Detect when we can merge multiple adjacent pieces, or even
@@ -1706,7 +1707,7 @@ void FrameEmitterImpl::emitCFIInstruction(const MCCFIInstruction &Instr) {
         encodeDwarfRegisterLocation(VR.Register, OSBlock);
         OSBlock << uint8_t(dwarf::DW_OP_bit_piece);
         encodeULEB128(VR.SizeInBits, OSBlock);
-        encodeULEB128(VR.SizeInBits * VR.Lane, OSBlock);
+        encodeULEB128(static_cast<uint64_t>(VR.SizeInBits) * VR.Lane, OSBlock);
       }
     }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/224647


More information about the llvm-commits mailing list