Skip to content

Commit e2791ae

Browse files
authored
fix unstacking issue with more than 400 elements in an array (#133)
1 parent 08517d2 commit e2791ae

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

json-smart/src/main/java/net/minidev/json/parser/JSONParserBase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ protected <T> T readObject(JsonReaderI<T> mapper) throws ParseException, IOExcep
620620
// should loop skipping read step
621621
skipSpace();
622622
if (c == '}') {
623+
this.depth--;
623624
read(); /* unstack */
624625
//
625626
return mapper.convert(current);

json-smart/src/test/java/net/minidev/json/test/TestOverflow.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.minidev.json.test;
22

3+
import net.minidev.json.JSONArray;
34
import net.minidev.json.JSONValue;
45
import net.minidev.json.parser.ParseException;
56

@@ -29,4 +30,21 @@ public void stressTest() throws Exception {
2930
}
3031
assertTrue(false);
3132
}
33+
34+
@Test
35+
public void shouldNotFailParsingArraysWith400Elements() throws Exception {
36+
int size = 400;
37+
StringBuilder sb = new StringBuilder();
38+
sb.append("[");
39+
for (int i=0; i < size; i++) {
40+
sb.append("{a:true}");
41+
if(i+1 < size) {
42+
sb.append(",");
43+
}
44+
}
45+
sb.append("]");
46+
String s = sb.toString();
47+
JSONArray array = (JSONArray) JSONValue.parseWithException(s);
48+
assertEquals(array.size(), size);
49+
}
3250
}

0 commit comments

Comments
 (0)