Skip to content

Commit 888eec8

Browse files
committed
Incorrect recursion depth check in JSONTokener
1 parent 677aba5 commit 888eec8

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/main/java/org/codehaus/jettison/json/JSONTokener.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -426,12 +426,16 @@ public Object nextValue() throws JSONException {
426426

427427
protected JSONObject newJSONObject() throws JSONException {
428428
checkRecursionDepth();
429-
return new JSONObject(this);
429+
JSONObject object = new JSONObject(this);
430+
recursionDepth--;
431+
return object;
430432
}
431433

432434
protected JSONArray newJSONArray() throws JSONException {
433435
checkRecursionDepth();
434-
return new JSONArray(this);
436+
JSONArray array = new JSONArray(this);
437+
recursionDepth--;
438+
return array;
435439
}
436440

437441
private void checkRecursionDepth() throws JSONException {

src/test/java/org/codehaus/jettison/json/JSONArrayTest.java

+6
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,10 @@ public void testInfiniteLoop2() {
6363
// expected
6464
}
6565
}
66+
67+
public void testIssue52() throws JSONException {
68+
new JSONObject().setRecursionDepthLimit(10);
69+
new JSONArray("[{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {a:10}]");
70+
}
71+
6672
}

0 commit comments

Comments
 (0)