[Support] Fix the overflow bug in ULEB128 decoding.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216268 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alex Lorenz 2014-08-22 16:29:45 +00:00
parent cc59c3f335
commit 4ef54c3f85
2 changed files with 2 additions and 1 deletions

View File

@ -82,7 +82,7 @@ inline uint64_t decodeULEB128(const uint8_t *p, unsigned *n = nullptr) {
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)

View File

@ -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");