[PATCH] D63645: [Support] Fix error handling in DataExtractor::get[US]LEB128
Pavel Labath via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 24 02:12:12 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL364169: [Support] Fix error handling in DataExtractor::get[US]LEB128 (authored by labath, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D63645?vs=205975&id=206169#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D63645/new/
https://reviews.llvm.org/D63645
Files:
llvm/trunk/lib/Support/DataExtractor.cpp
llvm/trunk/unittests/Support/DataExtractorTest.cpp
Index: llvm/trunk/lib/Support/DataExtractor.cpp
===================================================================
--- llvm/trunk/lib/Support/DataExtractor.cpp
+++ llvm/trunk/lib/Support/DataExtractor.cpp
@@ -157,12 +157,12 @@
byte = Data[offset++];
result |= uint64_t(byte & 0x7f) << shift;
shift += 7;
- if ((byte & 0x80) == 0)
- break;
+ if ((byte & 0x80) == 0) {
+ *offset_ptr = offset;
+ return result;
+ }
}
-
- *offset_ptr = offset;
- return result;
+ return 0;
}
int64_t DataExtractor::getSLEB128(uint32_t *offset_ptr) const {
@@ -178,14 +178,14 @@
byte = Data[offset++];
result |= uint64_t(byte & 0x7f) << shift;
shift += 7;
- if ((byte & 0x80) == 0)
- break;
+ if ((byte & 0x80) == 0) {
+ // Sign bit of byte is 2nd high order bit (0x40)
+ if (shift < 64 && (byte & 0x40))
+ result |= -(1ULL << shift);
+
+ *offset_ptr = offset;
+ return result;
+ }
}
-
- // Sign bit of byte is 2nd high order bit (0x40)
- if (shift < 64 && (byte & 0x40))
- result |= -(1ULL << shift);
-
- *offset_ptr = offset;
- return result;
+ return 0;
}
Index: llvm/trunk/unittests/Support/DataExtractorTest.cpp
===================================================================
--- llvm/trunk/unittests/Support/DataExtractorTest.cpp
+++ llvm/trunk/unittests/Support/DataExtractorTest.cpp
@@ -116,4 +116,14 @@
EXPECT_EQ(8U, offset);
}
+TEST(DataExtractorTest, LEB128_error) {
+ DataExtractor DE(StringRef("\x81"), false, 8);
+ uint32_t Offset = 0;
+ EXPECT_EQ(0U, DE.getULEB128(&Offset));
+ EXPECT_EQ(0U, Offset);
+
+ Offset = 0;
+ EXPECT_EQ(0U, DE.getSLEB128(&Offset));
+ EXPECT_EQ(0U, Offset);
+}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63645.206169.patch
Type: text/x-patch
Size: 1717 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190624/e8d8f02f/attachment.bin>
More information about the llvm-commits
mailing list