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]当字符串存在大量需要转义字符时出现数组越界异常 #1025

Closed
wangping2012 opened this issue Dec 20, 2022 · 3 comments
Closed
Labels
bug Something isn't working fixed
Milestone

Comments

@wangping2012
Copy link

问题描述

当字符串存在大量需要转义字符时出现数组越界异常

环境信息

请填写以下信息:

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

重现步骤

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

  1. 8000长度字符串
  2. 设置其中2000为不可显字符
  3. 序列化出现错误
    StringBuilder sb = new StrinqBuilder();
    for(int i =0;i<8000;i++) {
        sb .append("A");
    }
    byte[] temp = sb.tostring ().getBytes ("UTF-8") ;
    for(int i =0;i<2000;i++) {
        temp[i] =0x01;
    }
    try{
        System.out.printIn(JSON.toJSONString(new String(temp,"UTE-8"))) ;
    catch(Exception e) {
        e.printStackTrace();
    }

期待的正确结果

正确序列化

@wangping2012 wangping2012 added the bug Something isn't working label Dec 20, 2022
@wenshao wenshao added this to the 2.0.22 milestone Dec 20, 2022
@wenshao wenshao added the fixed label Dec 21, 2022
@wenshao
Copy link
Member

wenshao commented Dec 21, 2022

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.22-SNAPSHOT/
问题已修复,请帮忙用2.0.22-SNAPSHOT版本验证,2.0.22版本预计在元旦期间发布

@wangping2012
Copy link
Author

验证了,没问题

@wenshao
Copy link
Member

wenshao commented Dec 31, 2022

https://github.com/alibaba/fastjson2/releases/tag/2.0.22
问题已修复,请用新版本

@wenshao wenshao closed this as completed Dec 31, 2022
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