summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Andreas Gampe <agampe@google.com> 2018-07-10 17:19:00 -0700
committer Andreas Gampe <agampe@google.com> 2018-07-10 17:19:00 -0700
commitc1528176838174896afc001c3ebbc8b8ba06412c (patch)
treee7f33e67f9eed91266829449396f90ee9a3ef1e9
parent848f0d9782e467deb35b0ad3a904aeefbc9ef802 (diff)
ART: Correctly compare in UTF-16 space
When trying to cache the locations of constructor names, actually take care of using UTF-16 comparison, as the string table may contain strings with UTF-16 codepoints that are incompatible with strcmp. Add a crafted test to dex_file_verifier_test Bug: 110157789 Bug: 78568168 Test: m test-art-host Change-Id: Ifce56e53522eac2d421b316761ef0adfe341a5b9
-rw-r--r--libdexfile/dex/dex_file_verifier.cc2
-rw-r--r--libdexfile/dex/dex_file_verifier_test.cc15
2 files changed, 16 insertions, 1 deletions
diff --git a/libdexfile/dex/dex_file_verifier.cc b/libdexfile/dex/dex_file_verifier.cc
index d4359458d3..fda6376454 100644
--- a/libdexfile/dex/dex_file_verifier.cc
+++ b/libdexfile/dex/dex_file_verifier.cc
@@ -3056,7 +3056,7 @@ void DexFileVerifier::FindStringRangesForMethodNames() {
return reinterpret_cast<const char*>(str_data_ptr);
};
auto compare = [&get_string](const DexFile::StringId& lhs, const char* rhs) {
- return strcmp(get_string(lhs), rhs) < 0;
+ return CompareModifiedUtf8ToModifiedUtf8AsUtf16CodePointValues(get_string(lhs), rhs) < 0;
};
// '=' follows '<'
diff --git a/libdexfile/dex/dex_file_verifier_test.cc b/libdexfile/dex/dex_file_verifier_test.cc
index c9bac0fef2..65448cabd1 100644
--- a/libdexfile/dex/dex_file_verifier_test.cc
+++ b/libdexfile/dex/dex_file_verifier_test.cc
@@ -176,6 +176,21 @@ TEST_F(DexFileVerifierTest, MethodId) {
"Bad index for method flags verification");
}
+TEST_F(DexFileVerifierTest, InitCachingWithUnicode) {
+ static const char kInitWithUnicode[] =
+ "ZGV4CjAzNQDhN60rgMnSK13MoRscTuD+NZe7f6rIkHAAAgAAcAAAAHhWNBIAAAAAAAAAAGwBAAAJ"
+ "AAAAcAAAAAMAAACUAAAAAQAAAKAAAAAAAAAAAAAAAAIAAACsAAAAAQAAALwAAAAkAQAA3AAAANwA"
+ "AADgAAAA5gAAAO4AAAD1AAAAAQEAABUBAAAgAQAAIwEAAAQAAAAFAAAABwAAAAcAAAACAAAAAAAA"
+ "AAAAAAACAAAAAQAAAAIAAAAAAAAAAAAAAAEAAAAAAAAABgAAAAAAAABgAQAAAAAAAAHAgAACwIDA"
+ "gAAGPGluaXQ+AAVIZWxsbwAKTFRlc3RTeW5jOwASTGphdmEvbGFuZy9PYmplY3Q7AAlNYWluLmph"
+ "dmEAAVYABVdvcmxkAAAAAAAAAAYABw4AAAAACgABAAEAAAAwAQAADAAAAHAQAQAJABoBAwAaAggA"
+ "GgMAABoEAQAOAAAAAQAAgIAEuAIAAAwAAAAAAAAAAQAAAAAAAAABAAAACQAAAHAAAAACAAAAAwAA"
+ "AJQAAAADAAAAAQAAAKAAAAAFAAAAAgAAAKwAAAAGAAAAAQAAALwAAAACIAAACQAAANwAAAADEAAA"
+ "AQAAACwBAAADIAAAAQAAADABAAABIAAAAQAAADgBAAAAIAAAAQAAAGABAAAAEAAAAQAAAGwBAAA=";
+ // Just ensure it verifies w/o modification.
+ VerifyModification(kInitWithUnicode, "init_with_unicode", [](DexFile*) {}, nullptr);
+}
+
// Method flags test class generated from the following smali code. The declared-synchronized
// flags are there to enforce a 3-byte uLEB128 encoding so we don't have to relayout
// the code, but we need to remove them before doing tests.