[PATCH] [Support] fix the ULEB128 decoding bug.
Duncan P. N. Exon Smith
dexonsmith at apple.com
Fri Aug 22 09:33:28 PDT 2014
Ouch. LGTM!
> On 2014-Aug-22, at 09:30, Alex Lorenz <arphaman at gmail.com> wrote:
>
> 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");
> <D5029.12845.patch>
More information about the llvm-commits
mailing list