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] 当map的key为14位字符串时,有第8位不同其它位相同的两个key时,在反序列化mep的key仅会保留一个丢失掉一个 #2409

Closed
milabi opened this issue Apr 8, 2024 · 4 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@milabi
Copy link
Contributor

milabi commented Apr 8, 2024

问题描述

当数据为UTF-8编码反序列化时,当map中的key为14位时,有第8位不同其它位相同时,mep的key仅会保留一个丢失掉一个

环境信息

请填写以下信息:

  • OS信息: [e.g.:Windows 10 ]
  • JDK信息: [e.g.:Openjdk 11]
  • 版本信息:[e.g.:Fastjson2.0.48]

重现步骤

  1. 案例
    public static void main(String[] args) {
        String s = "{\"CABCB9281415LR\":{\"key\":\"CABCB9281415LR\",\"type\":\"分类1\"},\"CABCB9261415LR\":{\"key\":\"CABCB9261415LR\",\"type\":\"分类2\"}}";
        byte[] bytes = s.getBytes(StandardCharsets.UTF_8);
        JSONObject jsonObject = JSON.parseObject(bytes);
        System.out.println(jsonObject);
    }
  1. 输出结果
{"CABCB9281415LR":{"key":"CABCB9261415LR","type":"分类2"}}

期待的正确结果

{"CABCB9281415LR":{"key":"CABCB9281415LR","type":"分类1"},"CABCB9261415LR":{"key":"CABCB9261415LR","type":"分类2"}}

相关日志输出

Connected to the target VM, address: '127.0.0.1:58881', transport: 'socket'
{"CABCB9281415LR":{"key":"CABCB9261415LR","type":"分类2"}}
Disconnected from the target VM, address: '127.0.0.1:58881', transport: 'socket'

附加信息

https://github.com/alibaba/fastjson2/blob/1fa051eb6b497ef6c55b0ebfd811e783329221ba/core/src/main/java/com/alibaba/fastjson2/JSONReaderUTF8.java#L3358C33-L3358C71

com.alibaba.fastjson2.JSONReaderUTF8代码中3358行的nameValue1应该+7而不是+8

                    case 14:
                        nameValue0
                                = (((long) bytes[nameBegin + 5]) << 40)
                                + (((long) bytes[nameBegin + 4]) << 32)
                                + (((long) bytes[nameBegin + 3]) << 24)
                                + (((long) bytes[nameBegin + 2]) << 16)
                                + (((long) bytes[nameBegin + 1]) << 8)
                                + ((long) bytes[nameBegin]);
                        nameValue1
                                = (((long) bytes[nameBegin + 13]) << 56)
                                + (((long) bytes[nameBegin + 12]) << 48)
                                + (((long) bytes[nameBegin + 11]) << 40)
                                + (((long) bytes[nameBegin + 10]) << 32)
                                + (((long) bytes[nameBegin + 9]) << 24)
                                + (((long) bytes[nameBegin + 8]) << 16)
                                + (((long) bytes[nameBegin + 8]) << 8) // 这边应该为:(((long) bytes[nameBegin + 7]) << 8)
                                + ((long) bytes[nameBegin + 6]);
                        break;
@milabi milabi added the bug Something isn't working label Apr 8, 2024
@wenshao wenshao added this to the 2.0.49 milestone Apr 8, 2024
@wenshao
Copy link
Member

wenshao commented Apr 8, 2024

可以帮提交个PR么?

@wenshao
Copy link
Member

wenshao commented Apr 9, 2024

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.49-SNAPSHOT/
请帮忙用2.0.49-SNAPSHOT校验,2.0.49版本预计在4月下旬发布,可能是4月21日

@wenshao wenshao added the fixed label Apr 9, 2024
@milabi
Copy link
Contributor Author

milabi commented Apr 10, 2024

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.49-SNAPSHOT/ 请帮忙用2.0.49-SNAPSHOT校验,2.0.49版本预计在4月下旬发布,可能是4月21日

已校验可以

@wenshao
Copy link
Member

wenshao commented Apr 14, 2024

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

@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