diff --git a/libdexfile/dex/type_lookup_table.cc b/libdexfile/dex/type_lookup_table.cc index 4d20e04f03..eaa35f5b61 100644 --- a/libdexfile/dex/type_lookup_table.cc +++ b/libdexfile/dex/type_lookup_table.cc @@ -107,7 +107,7 @@ uint32_t TypeLookupTable::Lookup(const char* str, uint32_t hash) const { return dex::kDexNoIndex; } // Look for the partial hash match first, even if traversing the wrong bucket's chain. - uint32_t compared_hash_bits = (hash << mask_bits_) >> (2 * mask_bits_); + uint32_t compared_hash_bits = static_cast<uint64_t>(hash << mask_bits_) >> (2 * mask_bits_); while (compared_hash_bits != entry->GetHashBits(mask_bits_)) { if (entry->IsLast(mask_bits_)) { return dex::kDexNoIndex; diff --git a/libdexfile/dex/type_lookup_table.h b/libdexfile/dex/type_lookup_table.h index a668e62702..6619c848b2 100644 --- a/libdexfile/dex/type_lookup_table.h +++ b/libdexfile/dex/type_lookup_table.h @@ -147,7 +147,7 @@ class TypeLookupTable { uint32_t GetHashBits(uint32_t mask_bits) const { DCHECK_LE(mask_bits, 16u); - return data_ >> (2u * mask_bits); + return static_cast<uint64_t>(data_) >> (2u * mask_bits); } static uint32_t GetMask(uint32_t mask_bits) { diff --git a/test/836-32768classes/classes.dex b/test/836-32768classes/classes.dex new file mode 100644 index 0000000000..c3c4c49137 Binary files /dev/null and b/test/836-32768classes/classes.dex differ diff --git a/test/836-32768classes/expected-stderr.txt b/test/836-32768classes/expected-stderr.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/836-32768classes/expected-stdout.txt b/test/836-32768classes/expected-stdout.txt new file mode 100644 index 0000000000..980a0d5f19 --- /dev/null +++ b/test/836-32768classes/expected-stdout.txt @@ -0,0 +1 @@ +Hello World! diff --git a/test/836-32768classes/info.txt b/test/836-32768classes/info.txt new file mode 100644 index 0000000000..7eabe62bfc --- /dev/null +++ b/test/836-32768classes/info.txt @@ -0,0 +1,2 @@ +Regression test for a dex file with 32768 classes. We used to rely on undefined +shift behavior in the type lookup table code.