Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-7263: Improved parsing of DEX code_item

Ryan Kurtza66947f79c4b
diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/format/CodeItem.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/format/CodeItem.java
index 5546109f50..e812842bbf 100644
--- a/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/format/CodeItem.java
+++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/file/formats/android/dex/format/CodeItem.java
@@ -4,9 +4,9 @@
* 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.
@@ -70,10 +70,15 @@ public class CodeItem implements StructConverter {
instructionBytes = new byte[0];
instructions = new short[0];
}
- else {
+ else if (instructionSize > 0 && reader.isValidIndex(
+ reader.getPointerIndex() + (instructionSize * BinaryReader.SIZEOF_SHORT) - 1)) {
instructionBytes = reader.readByteArray(reader.getPointerIndex(), instructionSize * 2);
instructions = reader.readNextShortArray(instructionSize);
}
+ else {
+ throw new IOException(
+ "code_item.insns_size is too large: %d".formatted(instructionSize));
+ }
if (hasPadding()) {
padding = reader.readNextShort();
}