fastjson2 icon indicating copy to clipboard operation
fastjson2 copied to clipboard

[BUG] JSONB 序列化特定的JSON是报数组溢出错误

Open jimichenx opened this issue 4 years ago • 5 comments

问题描述

JSONB 序列化特定的JSON是报数组溢出错误,测试JOSN文件在 test.json.zip

环境信息

请填写以下信息:

  • OS信息: [e.g.:CentOS 8.4.2105 4Core 3.10GHz 16 GB]
  • JDK信息: [e.g.:Openjdk 17]
  • 版本信息:[e.g.:Fastjson2 2.0.12]

重现步骤

如何操作可以重现该问题:

  1. 使用 JSONB.toBytes 方法
  2. 输入 附件中的test.json 数据
  3. 出现 错误
    val json = File("test.json").readText()

    val map = JSON.parseObject(json)

    val bytes = JSONB.toBytes(map)

期待的正确结果

别爆出异常

相关日志输出

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: arraycopy: last destination index 274141 out of bounds for byte[274140] at java.base/java.lang.System.arraycopy(Native Method) at com.alibaba.fastjson2.JSONWriterJSONB.writeString(JSONWriterJSONB.java:575) at com.alibaba.fastjson2.writer.ObjectWriterImplMap.writeJSONB(ObjectWriterImplMap.java:257) at com.alibaba.fastjson2.JSONB.toBytes(JSONB.java:793) at TestKt.main(Test.kt:15) at TestKt.main(Test.kt)

附加信息

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

test.json.zip

jimichenx avatar Sep 08 '22 14:09 jimichenx

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.13-SNAPSHOT/ 问题已经修复,请用2.0.13-SNAPSHOT版本帮忙验证,2.0.13版本预计9月12日发布

wenshao avatar Sep 08 '22 23:09 wenshao

测试了 fastjson2-2.0.13-20220907.220828-61.jar 应该没有被修复

jimichenx avatar Sep 09 '22 02:09 jimichenx

我本地测试已经是修复,能更新到fastjson2-2.0.13-20220909.000016-65.jar 再帮忙验证下么?

如果还是报错,提供下更新后错误堆栈信息

wenshao avatar Sep 09 '22 09:09 wenshao

https://github.com/alibaba/fastjson2/releases/tag/2.0.13 2.0.13版本已经发布,请用帮忙用新版本验证

wenshao avatar Sep 10 '22 07:09 wenshao

可以了👍

jimichenx avatar Sep 10 '22 10:09 jimichenx