Description
ArrayIndexOutOfBoundsException is thrown when JSON.parse(new String("\0.")); called
Environment
- OS: Ubuntu 22.04 16Core 32 GB
- JDK: OpenJDK Runtime Environment (build 17.0.13+11-Ubuntu-2ubuntu122.04)
- commit:67871d7a0c36d2493d5594b57a717cce6d1f6787
Steps to reproduce:
- Use method
JSON.parse
- Input data - string of any legth, which ends with "\0." where "\0" is null-byte (int('\0') = 0)
- Error happens
public class TestIssue{
public static void main(String[] args){
try{
JSON.parse(new String("\0."));
} catch (JSONException ignored) {
System.out.println("Got JSONException");
}
}
}
Correct result
Got JSONException
Actual Result
Exception: java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2
at com.alibaba.fastjson2.JSONReaderUTF8.readNumber0(JSONReaderUTF8.java:5239)
at com.alibaba.fastjson2.JSONReader.readNumber(JSONReader.java:2239)
at com.alibaba.fastjson2.reader.ObjectReaderImplObject.readObject(ObjectReaderImplObject.java:290)
at com.alibaba.fastjson2.JSON.parse(JSON.java:150)
Additional information
In my opition JSONException must be thrown in this case but not unhandled ArrayIndexOutOfBounds exception
Found with Jazzer
Description
ArrayIndexOutOfBoundsException is thrown when JSON.parse(new String("\0.")); called
Environment
Steps to reproduce:
JSON.parseCorrect result
Got JSONExceptionActual Result
Additional information
In my opition JSONException must be thrown in this case but not unhandled ArrayIndexOutOfBounds exception
Found with Jazzer