[llvm] r216268 - [Support] Fix the overflow bug in ULEB128 decoding.

Alex Lorenz arphaman at gmail.com
Fri Aug 22 09:29:45 PDT 2014


Author: arphaman
Date: Fri Aug 22 11:29:45 2014
New Revision: 216268

URL: http://llvm.org/viewvc/llvm-project?rev=216268&view=rev
Log:
[Support] Fix the overflow bug in ULEB128 decoding.

Differential Revision: http://reviews.llvm.org/D5029

Modified:
    llvm/trunk/include/llvm/Support/LEB128.h
    llvm/trunk/unittests/Support/LEB128Test.cpp

Modified: llvm/trunk/include/llvm/Support/LEB128.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/LEB128.h?rev=216268&r1=216267&r2=216268&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/LEB128.h (original)
+++ llvm/trunk/include/llvm/Support/LEB128.h Fri Aug 22 11:29:45 2014
@@ -82,7 +82,7 @@ inline uint64_t decodeULEB128(const uint
   uint64_t Value = 0;
   unsigned Shift = 0;
   do {
-    Value += (*p & 0x7f) << Shift;
+    Value += uint64_t(*p & 0x7f) << Shift;
     Shift += 7;
   } while (*p++ >= 128);
   if (n)

Modified: llvm/trunk/unittests/Support/LEB128Test.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/LEB128Test.cpp?rev=216268&r1=216267&r2=216268&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/LEB128Test.cpp (original)
+++ llvm/trunk/unittests/Support/LEB128Test.cpp Fri Aug 22 11:29:45 2014
@@ -106,6 +106,7 @@ TEST(LEB128Test, DecodeULEB128) {
   EXPECT_DECODE_ULEB128_EQ(0xffu, "\xff\x01");
   EXPECT_DECODE_ULEB128_EQ(0x100u, "\x80\x02");
   EXPECT_DECODE_ULEB128_EQ(0x101u, "\x81\x02");
+  EXPECT_DECODE_ULEB128_EQ(4294975616ULL, "\x80\xc1\x80\x80\x10");
 
   // Decode ULEB128 with extra padding bytes
   EXPECT_DECODE_ULEB128_EQ(0u, "\x80\x00");





More information about the llvm-commits mailing list