Skip to content

[BUG] Multiple ArrayIndexOutOfBoundsException in JSONReaderUTF8.java, JSONReaderASCII.java, JSONReader.java #3883

@artemNasonov

Description

@artemNasonov

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:

  1. Use method JSON.parse
  2. Input data - string of any legth, which ends with "\0." where "\0" is null-byte (int('\0') = 0)
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixed

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions