From 45f5e0cb048b39ac9979922533b4b2dbbe2b2a6c Mon Sep 17 00:00:00 2001 From: Skylot Date: Sat, 16 Jun 2018 12:26:29 +0300 Subject: [PATCH] core: prevent endless loop in region construction (#267) --- .../dex/visitors/regions/RegionMaker.java | 22 +++++-------------- .../main/java/jadx/core/utils/DebugUtils.java | 2 +- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionMaker.java b/jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionMaker.java index fc5e6c69..e2f50358 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionMaker.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionMaker.java @@ -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; } diff --git a/jadx-core/src/main/java/jadx/core/utils/DebugUtils.java b/jadx-core/src/main/java/jadx/core/utils/DebugUtils.java index c930e96d..03f0e9f0 100644 --- a/jadx-core/src/main/java/jadx/core/utils/DebugUtils.java +++ b/jadx-core/src/main/java/jadx/core/utils/DebugUtils.java @@ -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); -- GitLab