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

[BUG] JSONWriterUTF16.writeName8Raw(long name)方法抛出java.lang.ArrayIndexOutOfBoundsException异常 #2419

Closed
plliang opened this issue Apr 9, 2024 · 3 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@plliang
Copy link

plliang commented Apr 9, 2024

问题描述

想要将一个大对象转换为JSON字符串,转换过程中抛出ArrayIndexOutOfBoundsException数组越界异常,debug截图如下:

FastJSON-Debug

进入该方法时,this.off == 27637,计算minCapacity判断是否扩容时,只增加了10个容量,此时27637 + 10 = 27647小于chars.length = 27648,判断为不需要扩容。在执行后续步骤时,实际上会取到11个偏移量,由于chars数组的最大下标为27647,因此造成数组越界。

环境信息

请填写以下信息:

  • OS信息: [Deepin 社区版(20.9) 8Core 3.00GHz 32 GB]
  • JDK信息: [openjdk version "11.0.9.1" 2020-11-04]
  • 版本信息:[Fastjson2 2.0.48]

重现步骤

示例代码如下(内部数据,无法提供):

JSON.config(JSONWriter.Feature.LargeObject, true);  
String jsonString = JSONObject.toJSONString(dataBasePO, SerializerFeature.DisableCircularReferenceDetect);

期待的正确结果

期望能够正确将对象转换为JSON字符串,不要抛出异常。或者通过某些配置能够实现正确转换

相关日志输出

com.alibaba.fastjson.JSONException: toJSONString error
	at com.alibaba.fastjson.JSON.toJSONString(JSON.java:1578)
	at com.uxsino.uxsync.core.infrastructure.repository.impl.MetaDataInFileRepositoryImpl.save(MetaDataInFileRepositoryImpl.java:62)
	at com.uxsino.uxsync.core.domain.service.MetaDataDomainService.save(MetaDataDomainService.java:48)
	at com.uxsino.uxsync.core.app.service.MetaDataAppService.refreshAll(MetaDataAppService.java:51)
	at com.uxsino.db.uxsync.metadata.domain.service.MetaDataDomainService.lambda$submitTask$0(MetaDataDomainService.java:151)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
	at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 27648 out of bounds for length 27648
	at com.alibaba.fastjson2.JSONWriterUTF16.writeName8Raw(JSONWriterUTF16.java:1719)
	at com.alibaba.fastjson2.writer.OWG_7_18_ColumnPO.write(Unknown Source)
	at com.alibaba.fastjson2.writer.FieldWriterList.writeListValue(FieldWriterList.java:218)
	at com.alibaba.fastjson2.writer.OWG_6_15_DataBasePO.write(Unknown Source)
	at com.alibaba.fastjson.JSON.toJSONString(JSON.java:1570)
	... 10 common frames omitted

附加信息

暂无其它信息提供

@plliang plliang added the bug Something isn't working label Apr 9, 2024
@wenshao wenshao added this to the 2.0.49 milestone Apr 9, 2024
@wenshao
Copy link
Member

wenshao commented Apr 12, 2024

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.49-SNAPSHOT/
问题已经修复,请帮忙用2.0.49-SNAPSHOT版本验证,2.0.49版本预计在本周末(4月14日)前发布

@plliang
Copy link
Author

plliang commented Apr 12, 2024

使用 fastjson2-2.0.49-20240412.055049-9.jar 包替换验证,能够成功转换JSON字符串。谢谢 @wenshao

@wenshao
Copy link
Member

wenshao commented Apr 14, 2024

@wenshao wenshao closed this as completed Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

2 participants