diff options
| author | 2017-08-10 15:30:26 +0100 | |
|---|---|---|
| committer | 2017-08-10 20:47:50 +0100 | |
| commit | 28453cf27c4f6ec194203a0227fbb5302d8c93f0 (patch) | |
| tree | ea2cbb70a487c33df3953b610d6923d632d492fb | |
| parent | b00c8b076714b779a2d34f581e849f33f407d6d8 (diff) | |
Fix dex file reading in VdexFile::GetNextDexFileData.
Dex files in a vdex file are always aligned.
bug: 64527414
Test: run-test --random-profile 663-odd-dex-size
Change-Id: I1e3b36e04b35ad3128eebee86f3166788162dec5
| -rw-r--r-- | runtime/dex_file_verifier.cc | 2 | ||||
| -rw-r--r-- | runtime/vdex_file.cc | 4 | ||||
| -rw-r--r-- | test/663-odd-dex-size/classes.dex | bin | 0 -> 733 bytes | |||
| -rw-r--r-- | test/663-odd-dex-size/expected.txt | 1 | ||||
| -rw-r--r-- | test/663-odd-dex-size/info.txt | 14 | ||||
| -rw-r--r-- | test/663-odd-dex-size2/663-odd-dex-size2.jar | bin | 0 -> 1136 bytes | |||
| -rw-r--r-- | test/663-odd-dex-size2/build | 17 | ||||
| -rw-r--r-- | test/663-odd-dex-size2/expected.txt | 1 | ||||
| -rw-r--r-- | test/663-odd-dex-size2/info.txt | 15 | ||||
| -rw-r--r-- | test/663-odd-dex-size3/663-odd-dex-size3.jar | bin | 0 -> 962 bytes | |||
| -rw-r--r-- | test/663-odd-dex-size3/build | 17 | ||||
| -rw-r--r-- | test/663-odd-dex-size3/expected.txt | 1 | ||||
| -rw-r--r-- | test/663-odd-dex-size3/info.txt | 19 | ||||
| -rw-r--r-- | test/663-odd-dex-size4/663-odd-dex-size4.jar | bin | 0 -> 962 bytes | |||
| -rw-r--r-- | test/663-odd-dex-size4/build | 17 | ||||
| -rw-r--r-- | test/663-odd-dex-size4/expected.txt | 1 | ||||
| -rw-r--r-- | test/663-odd-dex-size4/info.txt | 19 |
17 files changed, 127 insertions, 1 deletions
diff --git a/runtime/dex_file_verifier.cc b/runtime/dex_file_verifier.cc index c5c4eda98f..8fdd4706e4 100644 --- a/runtime/dex_file_verifier.cc +++ b/runtime/dex_file_verifier.cc @@ -363,7 +363,7 @@ bool DexFileVerifier::CheckHeader() { // Check file size from the header. uint32_t expected_size = header_->file_size_; if (size_ != expected_size) { - ErrorStringPrintf("Bad file size (%zd, expected %ud)", size_, expected_size); + ErrorStringPrintf("Bad file size (%zd, expected %u)", size_, expected_size); return false; } diff --git a/runtime/vdex_file.cc b/runtime/vdex_file.cc index e8f947c95a..b95522062e 100644 --- a/runtime/vdex_file.cc +++ b/runtime/vdex_file.cc @@ -20,6 +20,7 @@ #include <memory> +#include "base/bit_utils.h" #include "base/logging.h" #include "base/stl_util.h" #include "base/unix_file/fd_file.h" @@ -134,6 +135,9 @@ const uint8_t* VdexFile::GetNextDexFileData(const uint8_t* cursor) const { } else { // Fetch the next dex file. Return null if there is none. const uint8_t* data = cursor + reinterpret_cast<const DexFile::Header*>(cursor)->file_size_; + // Dex files are required to be 4 byte aligned. the OatWriter makes sure they are, see + // OatWriter::SeekToDexFiles. + data = AlignUp(data, 4); return (data == DexEnd()) ? nullptr : data; } } diff --git a/test/663-odd-dex-size/classes.dex b/test/663-odd-dex-size/classes.dex Binary files differnew file mode 100644 index 0000000000..633e3a2d70 --- /dev/null +++ b/test/663-odd-dex-size/classes.dex diff --git a/test/663-odd-dex-size/expected.txt b/test/663-odd-dex-size/expected.txt new file mode 100644 index 0000000000..3da1ec26e9 --- /dev/null +++ b/test/663-odd-dex-size/expected.txt @@ -0,0 +1 @@ +HelloWorld diff --git a/test/663-odd-dex-size/info.txt b/test/663-odd-dex-size/info.txt new file mode 100644 index 0000000000..11a50e039e --- /dev/null +++ b/test/663-odd-dex-size/info.txt @@ -0,0 +1,14 @@ +Test for a dex file with an odd size in a vdex file. + +The code in the file is: + +class Main { + public static void main(String[] args) { + System.out.println("HelloWorld"); + } +} + +The generated dex file was then manually edited to: +1) Add 1 to the size value in the dex header. +2) Add 1 byte to the file. +3) Change the checksum in the dex header. diff --git a/test/663-odd-dex-size2/663-odd-dex-size2.jar b/test/663-odd-dex-size2/663-odd-dex-size2.jar Binary files differnew file mode 100644 index 0000000000..a29224e503 --- /dev/null +++ b/test/663-odd-dex-size2/663-odd-dex-size2.jar diff --git a/test/663-odd-dex-size2/build b/test/663-odd-dex-size2/build new file mode 100644 index 0000000000..5636558dad --- /dev/null +++ b/test/663-odd-dex-size2/build @@ -0,0 +1,17 @@ +#!/bin/bash +# +# Copyright (C) 2017 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Nothing to do diff --git a/test/663-odd-dex-size2/expected.txt b/test/663-odd-dex-size2/expected.txt new file mode 100644 index 0000000000..3da1ec26e9 --- /dev/null +++ b/test/663-odd-dex-size2/expected.txt @@ -0,0 +1 @@ +HelloWorld diff --git a/test/663-odd-dex-size2/info.txt b/test/663-odd-dex-size2/info.txt new file mode 100644 index 0000000000..900394d74a --- /dev/null +++ b/test/663-odd-dex-size2/info.txt @@ -0,0 +1,15 @@ +Test for two files with an odd size in a vdex file. + +The code in boths file is: + +class Main { + public static void main(String[] args) { + System.out.println("HelloWorld"); + } +} + +The generated dex file was then manually edited to: +1) Add 1 to the size value in the dex header. +2) Add 1 byte to the file. +3) Change the checksum in the dex header. + diff --git a/test/663-odd-dex-size3/663-odd-dex-size3.jar b/test/663-odd-dex-size3/663-odd-dex-size3.jar Binary files differnew file mode 100644 index 0000000000..d23ed5787a --- /dev/null +++ b/test/663-odd-dex-size3/663-odd-dex-size3.jar diff --git a/test/663-odd-dex-size3/build b/test/663-odd-dex-size3/build new file mode 100644 index 0000000000..5636558dad --- /dev/null +++ b/test/663-odd-dex-size3/build @@ -0,0 +1,17 @@ +#!/bin/bash +# +# Copyright (C) 2017 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Nothing to do diff --git a/test/663-odd-dex-size3/expected.txt b/test/663-odd-dex-size3/expected.txt new file mode 100644 index 0000000000..3da1ec26e9 --- /dev/null +++ b/test/663-odd-dex-size3/expected.txt @@ -0,0 +1 @@ +HelloWorld diff --git a/test/663-odd-dex-size3/info.txt b/test/663-odd-dex-size3/info.txt new file mode 100644 index 0000000000..256c77de9c --- /dev/null +++ b/test/663-odd-dex-size3/info.txt @@ -0,0 +1,19 @@ +Test for a dex file with an odd size followed by an aligned dex file. + +The code in classes.dex is: + +class Main { + public static void main(String[] args) { + System.out.println("HelloWorld"); + } +} + +The generated dex file was then manually edited to: +1) Add 1 to the size value in the dex header. +2) Add 1 byte to the file. +3) Change the checksum in the dex header. + +The code in classes2.dex is: + +class Foo { +} diff --git a/test/663-odd-dex-size4/663-odd-dex-size4.jar b/test/663-odd-dex-size4/663-odd-dex-size4.jar Binary files differnew file mode 100644 index 0000000000..d229663605 --- /dev/null +++ b/test/663-odd-dex-size4/663-odd-dex-size4.jar diff --git a/test/663-odd-dex-size4/build b/test/663-odd-dex-size4/build new file mode 100644 index 0000000000..5636558dad --- /dev/null +++ b/test/663-odd-dex-size4/build @@ -0,0 +1,17 @@ +#!/bin/bash +# +# Copyright (C) 2017 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Nothing to do diff --git a/test/663-odd-dex-size4/expected.txt b/test/663-odd-dex-size4/expected.txt new file mode 100644 index 0000000000..3da1ec26e9 --- /dev/null +++ b/test/663-odd-dex-size4/expected.txt @@ -0,0 +1 @@ +HelloWorld diff --git a/test/663-odd-dex-size4/info.txt b/test/663-odd-dex-size4/info.txt new file mode 100644 index 0000000000..2c34557639 --- /dev/null +++ b/test/663-odd-dex-size4/info.txt @@ -0,0 +1,19 @@ +Test for an aligned dex file followed by a dex file with an odd size. + +The code in classes.dex is: + +class Foo { +} + +The code in classes2.dex is: + +class Main { + public static void main(String[] args) { + System.out.println("HelloWorld"); + } +} + +The generated dex file was then manually edited to: +1) Add 1 to the size value in the dex header. +2) Add 1 byte to the file. +3) Change the checksum in the dex header. |