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

David Blaikie dblaikie at gmail.com
Fri Aug 22 11:19:00 PDT 2014


On Fri, Aug 22, 2014 at 11:16 AM, Alex L <arphaman at gmail.com> wrote:
> I took a quick look at DebugInfo/DataExtractor, and the getULEB128 there is
> correct (it has the uint64_t conversion).
> But the question is why is the LEB128 decoding code is duplicated?

Yep, I had the same question when I saw one of them go in. One of the
reasons was the difference in source/dest API of the bytes (writing to
a hashing machine, writing to a stream, writing to a buffer, etc) - in
which case it should be templated in some way most likely, that I
never got around to implementing to address the duplication.

- David

>
>
> 2014-08-22 11:04 GMT-07:00 David Blaikie <dblaikie at gmail.com>:
>
>> So this scares me a bit - not because this fix isn't right (it looks
>> right to me) but because this isn't the only code that does (U)LEB
>> conversions. I think there's a couple of copies in debug info code...
>>
>> Could you check for them? Or I can try to dredge them up & take a glance.
>>
>> On Fri, Aug 22, 2014 at 9:29 AM, Alex Lorenz <arphaman at gmail.com> wrote:
>> > 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");
>> >
>> >
>> > _______________________________________________
>> > llvm-commits mailing list
>> > llvm-commits at cs.uiuc.edu
>> > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>



More information about the llvm-commits mailing list