Projects STRLCPY jadx Commits 26aa5045
🤬
  • core: guard endless regions processing

  • Loading...
  • Skylot committed 10 years ago
    26aa5045
    1 parent e4dde3f4
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■ ■
    jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionMaker.java
    skipped 27 lines
    28 28  import jadx.core.utils.ErrorsCounter;
    29 29  import jadx.core.utils.InstructionRemover;
    30 30  import jadx.core.utils.RegionUtils;
     31 +import jadx.core.utils.exceptions.JadxOverflowException;
    31 32   
    32 33  import java.util.ArrayList;
    33 34  import java.util.BitSet;
    skipped 15 lines
    49 50  public class RegionMaker {
    50 51   private static final Logger LOG = LoggerFactory.getLogger(RegionMaker.class);
    51 52   
     53 + // 'dumb' guard to prevent endless loop in regions processing
     54 + private static final int REGIONS_LIMIT = 1000 * 1000;
     55 + 
    52 56   private final MethodNode mth;
    53 57   private BitSet processedBlocks;
     58 + private int regionsCount;
    54 59   
    55 60   public RegionMaker(MethodNode mth) {
    56 61   this.mth = mth;
    skipped 10 lines
    67 72   } else {
    68 73   processedBlocks.set(id);
    69 74   }
     75 + }
     76 + regionsCount++;
     77 + if (regionsCount > REGIONS_LIMIT) {
     78 + throw new JadxOverflowException("Regions count limit reached");
    70 79   }
    71 80   
    72 81   Region r = new Region(stack.peekRegion());
    skipped 716 lines
  • ■ ■ ■ ■ ■ ■
    jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionStack.java
    skipped 2 lines
    3 3  import jadx.core.dex.nodes.BlockNode;
    4 4  import jadx.core.dex.nodes.IRegion;
    5 5  import jadx.core.dex.nodes.MethodNode;
     6 +import jadx.core.utils.exceptions.JadxOverflowException;
    6 7   
    7 8  import java.util.ArrayDeque;
    8 9  import java.util.Collection;
    skipped 7 lines
    16 17  final class RegionStack {
    17 18   private static final Logger LOG = LoggerFactory.getLogger(RegionStack.class);
    18 19   private static final boolean DEBUG = false;
     20 + 
     21 + private static final int REGIONS_STACK_LIMIT = 1000;
    19 22   
    20 23   static {
    21 24   if (DEBUG) {
    skipped 36 lines
    58 61   
    59 62   public void push(IRegion region) {
    60 63   stack.push(curState);
    61  - if (stack.size() > 1000) {
    62  - throw new StackOverflowError("Deep code hierarchy");
     64 + if (stack.size() > REGIONS_STACK_LIMIT) {
     65 + throw new JadxOverflowException("Regions stack size limit reached");
    63 66   }
    64 67   curState = curState.copy();
    65 68   curState.region = region;
    skipped 47 lines
  • ■ ■ ■ ■ ■
    jadx-core/src/main/java/jadx/core/utils/ErrorsCounter.java
    skipped 4 lines
    5 5  import jadx.core.dex.attributes.nodes.JadxErrorAttr;
    6 6  import jadx.core.dex.nodes.ClassNode;
    7 7  import jadx.core.dex.nodes.MethodNode;
     8 +import jadx.core.utils.exceptions.JadxOverflowException;
    8 9   
    9 10  import java.util.HashSet;
    10 11  import java.util.Set;
    skipped 21 lines
    32 33   errorsCount++;
    33 34   
    34 35   if (e != null) {
    35  - if (e.getClass() == StackOverflowError.class) {
     36 + if (e.getClass() == JadxOverflowException.class) {
    36 37   // don't print full stack trace
    37  - e = new StackOverflowError(e.getMessage());
     38 + e = new JadxOverflowException(e.getMessage());
    38 39   LOG.error(msg);
    39 40   } else {
    40 41   LOG.error(msg, e);
    skipped 59 lines
  • ■ ■ ■ ■ ■ ■
    jadx-core/src/main/java/jadx/core/utils/exceptions/JadxOverflowException.java
     1 +package jadx.core.utils.exceptions;
     2 + 
     3 +public class JadxOverflowException extends JadxRuntimeException {
     4 + public JadxOverflowException(String message) {
     5 + super(message);
     6 + }
     7 +}
     8 + 
Please wait...
Page is in error, reload to recover