[PATCH] [Support] fix the ULEB128 decoding bug.
Alex Lorenz
arphaman at gmail.com
Fri Aug 22 09:30:59 PDT 2014
Hi bob.wilson, bogner, dexonsmith,
This patch fixes the ULEB128 decoding which currently overflows when evaluating (*p & 0x7f) << Shift were *p = 0x10 and Shift is 28.
http://reviews.llvm.org/D5029
Files:
include/llvm/Support/LEB128.h
unittests/Support/LEB128Test.cpp
Index: include/llvm/Support/LEB128.h
===================================================================
--- include/llvm/Support/LEB128.h
+++ include/llvm/Support/LEB128.h
@@ -82,7 +82,7 @@
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)
Index: unittests/Support/LEB128Test.cpp
===================================================================
--- unittests/Support/LEB128Test.cpp
+++ unittests/Support/LEB128Test.cpp
@@ -106,6 +106,7 @@
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");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D5029.12845.patch
Type: text/x-patch
Size: 887 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140822/d4a10165/attachment.bin>
More information about the llvm-commits
mailing list