Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap StackOverflow with JSONException #660

Merged
merged 1 commit into from Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -30,7 +30,7 @@ subprojects {
}

group = 'org.json'
version = 'v20200429-SNAPSHOT'
version = 'v20211205-SNAPSHOT'
description = 'JSON in Java'
sourceCompatibility = '1.7'

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/json/JSONObject.java
Expand Up @@ -225,12 +225,19 @@ public JSONObject(JSONTokener x) throws JSONException {
throw x.syntaxError("A JSONObject text must begin with '{'");
}
for (;;) {
char prev = x.getPrevious();
c = x.nextClean();
switch (c) {
case 0:
throw x.syntaxError("A JSONObject text must end with '}'");
case '}':
return;
case '{':
case '[':
if(prev=='{') {
throw x.syntaxError("A JSON Object can not directly nest another JSON Object or JSON Array.");
}
// fall through
default:
x.back();
key = x.nextValue().toString();
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/org/json/JSONTokener.java
Expand Up @@ -209,6 +209,12 @@ public char next() throws JSONException {
this.previous = (char) c;
return this.previous;
}

/**
* Get the last character read from the input or '\0' if nothing has been read yet.
* @return the last character read from the input.
*/
protected char getPrevious() { return this.previous;}

/**
* Increments the internal indexes according to the previous character
Expand Down Expand Up @@ -428,10 +434,18 @@ public Object nextValue() throws JSONException {
return this.nextString(c);
case '{':
this.back();
return new JSONObject(this);
try {
return new JSONObject(this);
} catch (StackOverflowError e) {
throw new JSONException("JSON Array or Object depth too large to process.", e);
}
case '[':
this.back();
return new JSONArray(this);
try {
return new JSONArray(this);
} catch (StackOverflowError e) {
throw new JSONException("JSON Array or Object depth too large to process.", e);
}
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/json/junit/CDLTest.java
Expand Up @@ -190,7 +190,7 @@ public void badEscapedQuote(){
CDL.toJSONArray(badLine);
fail("Expecting an exception");
} catch (JSONException e) {
System.out.println("Message" + e.getMessage());
//System.out.println("Message" + e.getMessage());
assertEquals("Expecting an exception message",
"Bad character 'V' (86). at 20 [character 9 line 2]",
e.getMessage());
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/org/json/junit/JSONArrayTest.java
Expand Up @@ -29,8 +29,10 @@ of this software and associated documentation files (the "Software"), to deal
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
Expand All @@ -47,6 +49,7 @@ of this software and associated documentation files (the "Software"), to deal
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONPointerException;
import org.json.JSONTokener;
import org.junit.Test;

import com.jayway.jsonpath.Configuration;
Expand Down Expand Up @@ -1282,4 +1285,17 @@ public void jsonArrayClearMethodTest() {
assertTrue("expected jsonArray.length() == 0", jsonArray.length() == 0); //Check if its length is 0
jsonArray.getInt(0); //Should throws org.json.JSONException: JSONArray[0] not found
}

/**
* Tests for stack overflow. See https://github.com/stleary/JSON-java/issues/654
*/
@Test(expected = JSONException.class)
public void issue654StackOverflowInputWellFormed() {
//String input = new String(java.util.Base64.getDecoder().decode(base64Bytes));
final InputStream resourceAsStream = JSONObjectTest.class.getClassLoader().getResourceAsStream("Issue654WellFormedArray.json");
JSONTokener tokener = new JSONTokener(resourceAsStream);
JSONArray json_input = new JSONArray(tokener);
assertNotNull(json_input);
fail("Excepected Exception.");
}
}
47 changes: 47 additions & 0 deletions src/test/java/org/json/junit/JSONObjectTest.java
Expand Up @@ -35,6 +35,7 @@ of this software and associated documentation files (the "Software"), to deal
import static org.mockito.Mockito.when;

import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
Expand Down Expand Up @@ -3351,4 +3352,50 @@ public void jsonObjectClearMethodTest() {
assertTrue("expected jsonObject.length() == 0", jsonObject.length() == 0); //Check if its length is 0
jsonObject.getInt("key1"); //Should throws org.json.JSONException: JSONObject["asd"] not found
}

/**
* Tests for stack overflow. See https://github.com/stleary/JSON-java/issues/654
*/
@Test(expected = JSONException.class)
public void issue654StackOverflowInput() {
//String base64Bytes ="eyJHWiI6Wy0wLTAse3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e1stMC0wLHt7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3tbLTAtMCx7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3tbLTAtMCx7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7Wy0wLTAse3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3tbLTAtMCx7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7ewl7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7Wy0wLTAse3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e3t7e1stMCkw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{{{{{{{{{{{{{{{{{{{{{{{{{{{[-0-0,{{{{{{{{{{{{{{{{{{{{{{{{{{{{{[-0-0,{{{{{{{{{{s{{{{{{{";
JSONObject json_input = new JSONObject(input);
assertNotNull(json_input);
fail("Excepected Exception.");
}

/**
* Tests for incorrect object/array nesting. See https://github.com/stleary/JSON-java/issues/654
*/
@Test(expected = JSONException.class)
public void issue654IncorrectNestingNoKey1() {
JSONObject json_input = new JSONObject("{{\"a\":0}}");
assertNotNull(json_input);
fail("Excepected Exception.");
}

/**
* Tests for incorrect object/array nesting. See https://github.com/stleary/JSON-java/issues/654
*/
@Test(expected = JSONException.class)
public void issue654IncorrectNestingNoKey2() {
JSONObject json_input = new JSONObject("{[\"a\"]}");
assertNotNull(json_input);
fail("Excepected Exception.");
}

/**
* Tests for stack overflow. See https://github.com/stleary/JSON-java/issues/654
*/
@Test(expected = JSONException.class)
public void issue654StackOverflowInputWellFormed() {
//String input = new String(java.util.Base64.getDecoder().decode(base64Bytes));
final InputStream resourceAsStream = JSONObjectTest.class.getClassLoader().getResourceAsStream("Issue654WellFormedObject.json");
JSONTokener tokener = new JSONTokener(resourceAsStream);
JSONObject json_input = new JSONObject(tokener);
assertNotNull(json_input);
fail("Excepected Exception.");
}
}