Skip to content

Commit

Permalink
fix unstacking issue with more than 400 elements in an array (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
ewoelfel committed Mar 17, 2023
1 parent 08517d2 commit e2791ae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ protected <T> T readObject(JsonReaderI<T> mapper) throws ParseException, IOExcep
// should loop skipping read step
skipSpace();
if (c == '}') {
this.depth--;
read(); /* unstack */
//
return mapper.convert(current);
Expand Down
18 changes: 18 additions & 0 deletions json-smart/src/test/java/net/minidev/json/test/TestOverflow.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.minidev.json.test;

import net.minidev.json.JSONArray;
import net.minidev.json.JSONValue;
import net.minidev.json.parser.ParseException;

Expand Down Expand Up @@ -29,4 +30,21 @@ public void stressTest() throws Exception {
}
assertTrue(false);
}

@Test
public void shouldNotFailParsingArraysWith400Elements() throws Exception {
int size = 400;
StringBuilder sb = new StringBuilder();
sb.append("[");
for (int i=0; i < size; i++) {
sb.append("{a:true}");
if(i+1 < size) {
sb.append(",");
}
}
sb.append("]");
String s = sb.toString();
JSONArray array = (JSONArray) JSONValue.parseWithException(s);
assertEquals(array.size(), size);
}
}

2 comments on commit e2791ae

@comsmall
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it mean the CVE-2023-1370 has been fixed by this commit?

@UrielCh
Copy link
Contributor

@UrielCh UrielCh commented on e2791ae Mar 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nop, CVE-2023-1370 was fixed in this commit, this commit "fix the fix" since I forgot a this.depth-- in JSONParserBase.java

Version V2.4.10 is not affected by CVE-2023-1370.

Please sign in to comment.