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 void writeFloat 方法扩容引起的 java.lang.ArrayIndexOutOfBoundsException #860

Closed
magical1989 opened this issue Oct 21, 2022 · 6 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@magical1989
Copy link
Contributor

问题描述

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 8192
at com.alibaba.fastjson2.JSONWriterUTF16.writeFloat(JSONWriterUTF16.java:1198)
at com.alibaba.fastjson2.writer.ObjectWriterImplFloatValueArray.write(ObjectWriterImplFloatValueArray.java:26)
at com.alibaba.fastjson2.writer.ObjectWriterImplMap.write(ObjectWriterImplMap.java:459)
at com.alibaba.fastjson2.JSON.toJSONString(JSON.java:2010)

环境信息

  • JDK信息: [1.8.0_201-b09]
  • 版本信息:[Fastjson2 2.0.13]

重现步骤

  1. 出现 ArrayIndexOutOfBoundsException 错误
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;

import java.util.Arrays;

/**
 * @author lx11915
 */
public class ErrorMock {

    public static void main(String[] args) {
        float[] abc = new float[]{
                0.0044160923f,
                1.0449644E-4f,
                5.4759195E-5f,
                2.1139298E-5f,
                1.4655446E-5f,
                0.020943796f,
                0.012482191f,
                0.020476084f,
                0.011609814f,
                1.2344321f,
                0.3234f,
                234.1122f,
                0.23342f,
                1.2f,
                1.2344322f,
                0.3234f,
                234.1122f,
                0.23342f,
                1.2f,
                1.2344323f,
                1.88888f
        };
        // 这里是为了让b": 这里的的冒号正好到达8092长度
        // 需要在下一步进行扩容
        // 下面 12 改成 11 能正常扩容
        char[] hello = new char[(1<<13)-12]; 
        Arrays.fill(hello, '1');
        JSONObject object = new JSONObject();
        object.put("a", new String(hello));
        object.put("b", abc);
        System.out.println(JSON.toJSONString(object));
    }

}
  1. 具体debug位置
    image

期待的正确结果

image

相关日志输出

image

附加信息

大体应该是扩容那边缺少了当前偏移量off参与计算

@magical1989 magical1989 added the bug Something isn't working label Oct 21, 2022
@magical1989
Copy link
Contributor Author

@wenshao 顺便问下,能否在30号的2.0.16版本进行修复,这里线上大概千2的故障率,硬抗中。。

@wenshao
Copy link
Member

wenshao commented Oct 21, 2022

很抱歉,我争取在周末发布新版本修复

@wenshao
Copy link
Member

wenshao commented Oct 21, 2022

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.16-SNAPSHOT/
问题已修复,请用2.0.16-SNAPSHOT帮忙验证,2.0.16将会在23日(周日)发布

wenshao added a commit that referenced this issue Oct 21, 2022
@wenshao wenshao added this to the 2.0.16 milestone Oct 21, 2022
@wenshao wenshao added the fixed label Oct 21, 2022
@wenshao
Copy link
Member

wenshao commented Oct 22, 2022

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

@wenshao wenshao closed this as completed Oct 22, 2022
@magical1989
Copy link
Contributor Author

非常感谢温少,周末家中没有梯子,今早一来review了下,perfect!!
nice job. 待上线中了。。

@magical1989
Copy link
Contributor Author

image
well done. @wenshao

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