Skip to content

Commit

Permalink
fix: check if debug info offset is invalid (#1653)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Sep 11, 2024
1 parent b580708 commit fd80e03
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import jadx.core.dex.visitors.blocks.BlockSplitter;
import jadx.core.dex.visitors.ssa.SSATransform;
import jadx.core.utils.ListUtils;
import jadx.core.utils.exceptions.InvalidDataException;
import jadx.core.utils.exceptions.JadxException;

@JadxVisitor(
Expand All @@ -40,6 +41,8 @@ public void visit(MethodNode mth) throws JadxException {
if (debugInfo != null) {
processDebugInfo(mth, debugInfo);
}
} catch (InvalidDataException e) {
mth.addWarnComment(e.getMessage());
} catch (Exception e) {
mth.addWarnComment("Failed to parse debug info", e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package jadx.core.utils.exceptions;

public class InvalidDataException extends JadxRuntimeException {
public InvalidDataException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import jadx.api.plugins.input.data.impl.CatchData;
import jadx.api.plugins.input.data.impl.TryData;
import jadx.api.plugins.input.insns.InsnData;
import jadx.core.utils.exceptions.InvalidDataException;
import jadx.plugins.input.dex.DexException;
import jadx.plugins.input.dex.insns.DexInsnData;
import jadx.plugins.input.dex.insns.DexInsnFormat;
Expand Down Expand Up @@ -112,6 +113,9 @@ public IDebugInfo getDebugInfo() {
if (debugOff == 0) {
return null;
}
if (debugOff < 0 || debugOff > in.size()) {
throw new InvalidDataException("Invalid debug info offset");
}
int regsCount = getRegistersCount();
DebugInfoParser debugInfoParser = new DebugInfoParser(in, regsCount, getUnitsCount());
debugInfoParser.initMthArgs(regsCount, in.getMethodParamTypes(mthId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ public int readSleb128() {
return Leb128.readSignedLeb128(this);
}

public int size() {
return buf.capacity();
}

@Override
public String toString() {
return "SectionReader{buf=" + buf + ", offset=" + offset + '}';
Expand Down

0 comments on commit fd80e03

Please sign in to comment.