diff --git a/dexlib2/src/main/java/org/jf/dexlib2/analysis/MethodAnalyzer.java b/dexlib2/src/main/java/org/jf/dexlib2/analysis/MethodAnalyzer.java index eca9391f..f874f1b8 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/analysis/MethodAnalyzer.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/analysis/MethodAnalyzer.java @@ -499,11 +499,19 @@ public class MethodAnalyzer { OffsetInstruction offsetInstruction = (OffsetInstruction)instruction.instruction; if (instructionOpcode == Opcode.PACKED_SWITCH || instructionOpcode == Opcode.SPARSE_SWITCH) { - SwitchPayload switchPayload = (SwitchPayload)analyzedInstructions.get(instructionCodeAddress + - offsetInstruction.getCodeOffset()).instruction; + AnalyzedInstruction analyzedSwitchPayload = analyzedInstructions.get( + instructionCodeAddress + offsetInstruction.getCodeOffset()); + if (analyzedSwitchPayload == null) { + throw new AnalysisException("Invalid switch payload offset"); + } + SwitchPayload switchPayload = (SwitchPayload)analyzedSwitchPayload.instruction; + for (SwitchElement switchElement: switchPayload.getSwitchElements()) { AnalyzedInstruction targetInstruction = analyzedInstructions.get(instructionCodeAddress + switchElement.getOffset()); + if (targetInstruction == null) { + throw new AnalysisException("Invalid switch target offset"); + } addPredecessorSuccessor(instruction, targetInstruction, exceptionHandlers, instructionsToProcess);