Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
J
jadx
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
jadx
Commits
26aa5045
Commit
26aa5045
authored
Jun 17, 2014
by
Skylot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: guard endless regions processing
parent
e4dde3f4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
4 deletions
+24
-4
RegionMaker.java
...main/java/jadx/core/dex/visitors/regions/RegionMaker.java
+9
-0
RegionStack.java
...main/java/jadx/core/dex/visitors/regions/RegionStack.java
+5
-2
ErrorsCounter.java
jadx-core/src/main/java/jadx/core/utils/ErrorsCounter.java
+3
-2
JadxOverflowException.java
...ava/jadx/core/utils/exceptions/JadxOverflowException.java
+7
-0
No files found.
jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionMaker.java
View file @
26aa5045
...
@@ -28,6 +28,7 @@ import jadx.core.utils.BlockUtils;
...
@@ -28,6 +28,7 @@ import jadx.core.utils.BlockUtils;
import
jadx.core.utils.ErrorsCounter
;
import
jadx.core.utils.ErrorsCounter
;
import
jadx.core.utils.InstructionRemover
;
import
jadx.core.utils.InstructionRemover
;
import
jadx.core.utils.RegionUtils
;
import
jadx.core.utils.RegionUtils
;
import
jadx.core.utils.exceptions.JadxOverflowException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.BitSet
;
import
java.util.BitSet
;
...
@@ -49,8 +50,12 @@ import static jadx.core.utils.BlockUtils.selectOther;
...
@@ -49,8 +50,12 @@ import static jadx.core.utils.BlockUtils.selectOther;
public
class
RegionMaker
{
public
class
RegionMaker
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
RegionMaker
.
class
);
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
RegionMaker
.
class
);
// 'dumb' guard to prevent endless loop in regions processing
private
static
final
int
REGIONS_LIMIT
=
1000
*
1000
;
private
final
MethodNode
mth
;
private
final
MethodNode
mth
;
private
BitSet
processedBlocks
;
private
BitSet
processedBlocks
;
private
int
regionsCount
;
public
RegionMaker
(
MethodNode
mth
)
{
public
RegionMaker
(
MethodNode
mth
)
{
this
.
mth
=
mth
;
this
.
mth
=
mth
;
...
@@ -68,6 +73,10 @@ public class RegionMaker {
...
@@ -68,6 +73,10 @@ public class RegionMaker {
processedBlocks
.
set
(
id
);
processedBlocks
.
set
(
id
);
}
}
}
}
regionsCount
++;
if
(
regionsCount
>
REGIONS_LIMIT
)
{
throw
new
JadxOverflowException
(
"Regions count limit reached"
);
}
Region
r
=
new
Region
(
stack
.
peekRegion
());
Region
r
=
new
Region
(
stack
.
peekRegion
());
BlockNode
next
=
startBlock
;
BlockNode
next
=
startBlock
;
...
...
jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionStack.java
View file @
26aa5045
...
@@ -3,6 +3,7 @@ package jadx.core.dex.visitors.regions;
...
@@ -3,6 +3,7 @@ package jadx.core.dex.visitors.regions;
import
jadx.core.dex.nodes.BlockNode
;
import
jadx.core.dex.nodes.BlockNode
;
import
jadx.core.dex.nodes.IRegion
;
import
jadx.core.dex.nodes.IRegion
;
import
jadx.core.dex.nodes.MethodNode
;
import
jadx.core.dex.nodes.MethodNode
;
import
jadx.core.utils.exceptions.JadxOverflowException
;
import
java.util.ArrayDeque
;
import
java.util.ArrayDeque
;
import
java.util.Collection
;
import
java.util.Collection
;
...
@@ -17,6 +18,8 @@ final class RegionStack {
...
@@ -17,6 +18,8 @@ final class RegionStack {
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
RegionStack
.
class
);
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
RegionStack
.
class
);
private
static
final
boolean
DEBUG
=
false
;
private
static
final
boolean
DEBUG
=
false
;
private
static
final
int
REGIONS_STACK_LIMIT
=
1000
;
static
{
static
{
if
(
DEBUG
)
{
if
(
DEBUG
)
{
LOG
.
debug
(
"Debug enabled for {}"
,
RegionStack
.
class
);
LOG
.
debug
(
"Debug enabled for {}"
,
RegionStack
.
class
);
...
@@ -58,8 +61,8 @@ final class RegionStack {
...
@@ -58,8 +61,8 @@ final class RegionStack {
public
void
push
(
IRegion
region
)
{
public
void
push
(
IRegion
region
)
{
stack
.
push
(
curState
);
stack
.
push
(
curState
);
if
(
stack
.
size
()
>
1000
)
{
if
(
stack
.
size
()
>
REGIONS_STACK_LIMIT
)
{
throw
new
StackOverflowError
(
"Deep code hierarchy
"
);
throw
new
JadxOverflowException
(
"Regions stack size limit reached
"
);
}
}
curState
=
curState
.
copy
();
curState
=
curState
.
copy
();
curState
.
region
=
region
;
curState
.
region
=
region
;
...
...
jadx-core/src/main/java/jadx/core/utils/ErrorsCounter.java
View file @
26aa5045
...
@@ -5,6 +5,7 @@ import jadx.core.dex.attributes.IAttributeNode;
...
@@ -5,6 +5,7 @@ import jadx.core.dex.attributes.IAttributeNode;
import
jadx.core.dex.attributes.nodes.JadxErrorAttr
;
import
jadx.core.dex.attributes.nodes.JadxErrorAttr
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.core.dex.nodes.ClassNode
;
import
jadx.core.dex.nodes.MethodNode
;
import
jadx.core.dex.nodes.MethodNode
;
import
jadx.core.utils.exceptions.JadxOverflowException
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.Set
;
import
java.util.Set
;
...
@@ -32,9 +33,9 @@ public class ErrorsCounter {
...
@@ -32,9 +33,9 @@ public class ErrorsCounter {
errorsCount
++;
errorsCount
++;
if
(
e
!=
null
)
{
if
(
e
!=
null
)
{
if
(
e
.
getClass
()
==
StackOverflowError
.
class
)
{
if
(
e
.
getClass
()
==
JadxOverflowException
.
class
)
{
// don't print full stack trace
// don't print full stack trace
e
=
new
StackOverflowError
(
e
.
getMessage
());
e
=
new
JadxOverflowException
(
e
.
getMessage
());
LOG
.
error
(
msg
);
LOG
.
error
(
msg
);
}
else
{
}
else
{
LOG
.
error
(
msg
,
e
);
LOG
.
error
(
msg
,
e
);
...
...
jadx-core/src/main/java/jadx/core/utils/exceptions/JadxOverflowException.java
0 → 100644
View file @
26aa5045
package
jadx
.
core
.
utils
.
exceptions
;
public
class
JadxOverflowException
extends
JadxRuntimeException
{
public
JadxOverflowException
(
String
message
)
{
super
(
message
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment