diff --git a/llvm/include/llvm/Support/LEB128.h b/llvm/include/llvm/Support/LEB128.h --- a/llvm/include/llvm/Support/LEB128.h +++ b/llvm/include/llvm/Support/LEB128.h @@ -134,7 +134,7 @@ if (error) *error = nullptr; do { - if (end && p == end) { + if (p == end) { if (error) *error = "malformed uleb128, extends past end"; if (n) @@ -168,7 +168,7 @@ if (error) *error = nullptr; do { - if (end && p == end) { + if (p == end) { if (error) *error = "malformed sleb128, extends past end"; if (n) diff --git a/llvm/unittests/Support/LEB128Test.cpp b/llvm/unittests/Support/LEB128Test.cpp --- a/llvm/unittests/Support/LEB128Test.cpp +++ b/llvm/unittests/Support/LEB128Test.cpp @@ -113,6 +113,9 @@ EXPECT_EQ(EXPECTED, Actual); \ } while (0) + // Don't crash + EXPECT_EQ(0u, decodeULEB128(nullptr, nullptr, nullptr)); + // Decode ULEB128 EXPECT_DECODE_ULEB128_EQ(0u, "\x00"); EXPECT_DECODE_ULEB128_EQ(1u, "\x01"); @@ -148,6 +151,9 @@ EXPECT_EQ(EXPECTED, Actual); \ } while (0) + // Don't crash + EXPECT_EQ(0, decodeSLEB128(nullptr, nullptr, nullptr)); + // Decode SLEB128 EXPECT_DECODE_SLEB128_EQ(0L, "\x00"); EXPECT_DECODE_SLEB128_EQ(1L, "\x01");