core: Fix possible NPE in DebugInfoParser.addrChange()

This may happen because MethodNode.unloadInsnArr() call from BlockSplitter.visit() - after it instructions[] become null.
So, try to reload method before processing its instructions array and bail if insnArr still null even after reloading method.
This commit is contained in:
S-trace
2020-01-03 04:16:22 +03:00
committed by Soul Trace
parent c72f2a2c96
commit 17cbb3eab0
2 changed files with 20 additions and 7 deletions
@@ -155,13 +155,8 @@ public class MethodNode extends LineAttrNode implements ILoadable, ICodeNode {
public void checkInstructions() {
List<RegisterArg> list = new ArrayList<>();
if (instructions == null) {
LOG.debug("Instructions == null, reloading method {}.{}", getClass().getName(), getName());
unload();
try {
load();
} catch (DecodeException e) {
throw new JadxRuntimeException("Failed to reload method " + getClass().getName() + "." + getName());
}
LOG.debug("instructions == null, reloading method {}.{}", getClass().getName(), getName());
reload();
}
for (InsnNode insnNode : instructions) {
if (insnNode == null) {
@@ -182,6 +177,15 @@ public class MethodNode extends LineAttrNode implements ILoadable, ICodeNode {
}
}
public void reload() {
unload();
try {
load();
} catch (DecodeException e) {
throw new JadxRuntimeException("Failed to reload method " + getClass().getName() + "." + getName());
}
}
public void initMethodTypes() {
List<ArgType> types = parseSignature();
if (types == null) {
@@ -48,6 +48,15 @@ public class DebugInfoParseVisitor extends AbstractVisitor {
private void processDebugInfo(MethodNode mth, int debugOffset) {
InsnNode[] insnArr = mth.getInstructions();
if (insnArr == null) {
LOG.debug("insnArr == null, reloading method {}.{}", getClass().getName(), mth.getName());
mth.reload();
insnArr = mth.getInstructions();
}
if (insnArr == null) {
LOG.error("insnArr == null even after reloading method {}.{} - bailing", getClass().getName(), mth.getName());
return;
}
DebugInfoParser debugInfoParser = new DebugInfoParser(mth, debugOffset, insnArr);
List<LocalVar> localVars = debugInfoParser.process();
attachDebugInfo(mth, localVars, insnArr);