Skip to content

[BUG]fastjson2.0.61版本,将字符串转成对象,如果数组型的字符串中含有\n回车,且字符串比较长,会出现数据越界异常。 #7685

Description

@mumuandcao

问题描述

fastjson2,将字符串转成对象,如果数组型的字符串中含有\n回车,且字符串比较长,会出现数据越界异常。

环境信息

  • OS信息: windows和linux
  • JDK信息:jdk-21.0.7
  • 版本信息:Fastjson2 2.0.61,其他版本没有这个问题,比如Fastjson2 2.0.60,Fastjson2 2.0.53,Fastjson2 2.0.54

重现步骤

  1. fastjson2,将字符串转成对象,如果数组型的字符串中含有\n回车,且字符串比较长,会出现数据越界异常。
  2. 可以执行运行如下代码
String str= "{\"Test\":[{\"message\":\"\\n\"},{\"message\":\"s Howard), dedicated to dinosaur conservation, was invited by Benjamin Lockwood. Benjamin and his subordinate Eli Mills (played by Rafi Spo) hope that she and relevant technicians will go to Isla Nublar to save the dinosaurs there and relocate them to a new habitat. Claire, who is infected, manages to bring Owen (played by Chris Pratt) along to go, while Owen hopes to rescue the velociraptor Blue that he has personally tamed. When they set foot on this isolated island, they found that things were not that simple.\\nVolcanoes are restless and ready to erupt, while ugly conspiracies are quietly brewing amidst chaos.\"}]}";
JSON.parseObject(str, Object.class);

期待的正确结果

对您期望发生的结果进行清晰简洁的描述。

相关日志输出

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: arraycopy: last destination index 516 out of bounds for char[512]
at java.base/java.lang.System.arraycopy(Native Method)
at com.alibaba.fastjson2.JSONReaderUTF16.readString(JSONReaderUTF16.java:3259)
at com.alibaba.fastjson2.JSONReader.readObject(JSONReader.java:3777)
at com.alibaba.fastjson2.JSONReader.readArray(JSONReader.java:4118)
at com.alibaba.fastjson2.reader.ObjectReaderImplObject.readObject(ObjectReaderImplObject.java:209)
at com.alibaba.fastjson2.JSON.parseObject(JSON.java:992)
at Test.main(Test.java:2222)

附加信息

如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions