diff options
Diffstat (limited to 'runtime/dex_file_test.cc')
-rw-r--r-- | runtime/dex_file_test.cc | 71 |
1 files changed, 10 insertions, 61 deletions
diff --git a/runtime/dex_file_test.cc b/runtime/dex_file_test.cc index 6a06177bb6..3dffc40011 100644 --- a/runtime/dex_file_test.cc +++ b/runtime/dex_file_test.cc @@ -26,6 +26,7 @@ #include "os.h" #include "scoped_thread_state_change.h" #include "thread-inl.h" +#include "utils.h" namespace art { @@ -37,65 +38,13 @@ TEST_F(DexFileTest, Open) { ASSERT_TRUE(dex.get() != nullptr); } -static const uint8_t kBase64Map[256] = { - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 62, 255, 255, 255, 63, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255, - 255, 254, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, - 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, // NOLINT - 19, 20, 21, 22, 23, 24, 25, 255, 255, 255, 255, 255, // NOLINT - 255, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, - 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, // NOLINT - 49, 50, 51, 255, 255, 255, 255, 255, 255, 255, 255, 255, // NOLINT - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255 -}; - -static inline std::vector<uint8_t> DecodeBase64(const char* src) { - std::vector<uint8_t> tmp; - uint32_t t = 0, y = 0; - int g = 3; - for (size_t i = 0; src[i] != '\0'; ++i) { - uint8_t c = kBase64Map[src[i] & 0xFF]; - if (c == 255) continue; - // the final = symbols are read and used to trim the remaining bytes - if (c == 254) { - c = 0; - // prevent g < 0 which would potentially allow an overflow later - if (--g < 0) { - return std::vector<uint8_t>(); - } - } else if (g != 3) { - // we only allow = to be at the end - return std::vector<uint8_t>(); - } - t = (t << 6) | c; - if (++y == 4) { - tmp.push_back((t >> 16) & 255); - if (g > 1) { - tmp.push_back((t >> 8) & 255); - } - if (g > 2) { - tmp.push_back(t & 255); - } - y = t = 0; - } - } - if (y != 0) { - return std::vector<uint8_t>(); - } - return tmp; +static inline std::vector<uint8_t> DecodeBase64Vec(const char* src) { + std::vector<uint8_t> res; + size_t size; + std::unique_ptr<uint8_t[]> data(DecodeBase64(src, &size)); + res.resize(size); + memcpy(res.data(), data.get(), size); + return res; } // Although this is the same content logically as the Nested test dex, @@ -166,7 +115,7 @@ static const char kRawDexZeroLength[] = static void DecodeAndWriteDexFile(const char* base64, const char* location) { // decode base64 CHECK(base64 != nullptr); - std::vector<uint8_t> dex_bytes = DecodeBase64(base64); + std::vector<uint8_t> dex_bytes = DecodeBase64Vec(base64); CHECK_NE(dex_bytes.size(), 0u); // write to provided file @@ -202,7 +151,7 @@ static std::unique_ptr<const DexFile> OpenDexFileInMemoryBase64(const char* base const char* location, uint32_t location_checksum) { CHECK(base64 != nullptr); - std::vector<uint8_t> dex_bytes = DecodeBase64(base64); + std::vector<uint8_t> dex_bytes = DecodeBase64Vec(base64); CHECK_NE(dex_bytes.size(), 0u); std::string error_message; |