Skip to content

Commit

Permalink
fix: increase region iterative traversal limit (#767)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Oct 27, 2019
1 parent f228a72 commit 9f06d67
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import jadx.core.dex.nodes.MethodNode;
import jadx.core.dex.trycatch.ExceptionHandler;
import jadx.core.utils.exceptions.JadxOverflowException;
import jadx.core.utils.exceptions.JadxRuntimeException;

public class DepthRegionTraversal {

private static final int ITERATIVE_LIMIT = 500;
private static final int ITERATIVE_LIMIT_MULTIPLIER = 5;

private DepthRegionTraversal() {
}
Expand All @@ -21,17 +22,21 @@ public static void traverse(MethodNode mth, IRegionVisitor visitor) {
public static void traverseIterative(MethodNode mth, IRegionIterativeVisitor visitor) {
boolean repeat;
int k = 0;
int limit = ITERATIVE_LIMIT_MULTIPLIER * mth.getBasicBlocks().size();
do {
repeat = traverseIterativeStepInternal(mth, visitor, mth.getRegion());
if (k++ > ITERATIVE_LIMIT) {
throw new JadxOverflowException("Iterative traversal limit reached, method: " + mth);
if (k++ > limit) {
throw new JadxRuntimeException("Iterative traversal limit reached: "
+ "limit: " + limit + ", visitor: " + visitor.getClass().getName()
+ ", blocks count: " + mth.getBasicBlocks().size());
}
} while (repeat);
}

public static void traverseIncludingExcHandlers(MethodNode mth, IRegionIterativeVisitor visitor) {
boolean repeat;
int k = 0;
int limit = ITERATIVE_LIMIT_MULTIPLIER * mth.getBasicBlocks().size();
do {
repeat = traverseIterativeStepInternal(mth, visitor, mth.getRegion());
if (!repeat) {
Expand All @@ -42,8 +47,10 @@ public static void traverseIncludingExcHandlers(MethodNode mth, IRegionIterative
}
}
}
if (k++ > ITERATIVE_LIMIT) {
throw new JadxOverflowException("Iterative traversal limit reached, method: " + mth);
if (k++ > limit) {
throw new JadxRuntimeException("Iterative traversal limit reached: "
+ "limit: " + limit + ", visitor: " + visitor.getClass().getName()
+ ", blocks count: " + mth.getBasicBlocks().size());
}
} while (repeat);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public class IfRegionVisitor extends AbstractVisitor {

@Override
public void visit(MethodNode mth) {
if (mth.isNoCode()) {
return;
}

DepthRegionTraversal.traverseIterative(mth, TERNARY_VISITOR);
DepthRegionTraversal.traverse(mth, PROCESS_IF_REGION_VISITOR);
DepthRegionTraversal.traverseIterative(mth, REMOVE_REDUNDANT_ELSE_VISITOR);
Expand Down

0 comments on commit 9f06d67

Please sign in to comment.