提交 45f5e0cb 编写于 作者: S Skylot

core: prevent endless loop in region construction (#267)

上级 7d983f28
......@@ -44,6 +44,7 @@ import jadx.core.utils.ErrorsCounter;
import jadx.core.utils.InstructionRemover;
import jadx.core.utils.RegionUtils;
import jadx.core.utils.exceptions.JadxOverflowException;
import jadx.core.utils.exceptions.JadxRuntimeException;
import static jadx.core.dex.visitors.regions.IfMakerHelper.confirmMerge;
import static jadx.core.dex.visitors.regions.IfMakerHelper.makeIfInfo;
......@@ -60,34 +61,21 @@ public class RegionMaker {
private static final int REGIONS_LIMIT = 1000 * 1000;
private final MethodNode mth;
private BitSet processedBlocks;
private int regionsCount;
public RegionMaker(MethodNode mth) {
this.mth = mth;
if (Consts.DEBUG) {
this.processedBlocks = new BitSet(mth.getBasicBlocks().size());
}
}
public Region makeRegion(BlockNode startBlock, RegionStack stack) {
if (Consts.DEBUG) {
int id = startBlock.getId();
if (processedBlocks.get(id)) {
LOG.debug(" Block already processed: {}, mth: {}", startBlock, mth);
} else {
processedBlocks.set(id);
}
}
regionsCount++;
if (regionsCount > REGIONS_LIMIT) {
throw new JadxOverflowException("Regions count limit reached");
}
Region r = new Region(stack.peekRegion());
BlockNode next = startBlock;
while (next != null) {
next = traverse(r, next, stack);
regionsCount++;
if (regionsCount > REGIONS_LIMIT) {
throw new JadxRuntimeException("Regions count limit reached");
}
}
return r;
}
......
......@@ -45,7 +45,7 @@ public class DebugUtils {
}
public static void dump(MethodNode mth, String desc) {
File out = new File("test-graph" + desc + "-tmp");
File out = new File("test-graph-" + desc + "-tmp");
DotGraphVisitor.dump().save(out, mth);
DotGraphVisitor.dumpRaw().save(out, mth);
DotGraphVisitor.dumpRegions().save(out, mth);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册