Skip to content

Cast error in 3.3 triple protocol #13809

@CHYhave

Description

@CHYhave
  • I have searched the issues of this repository and believe that this is not a duplicate.

Environment

  • Dubbo version: 3.3
  • Operating System version: Mac os
  • Java version: 17

Steps to reproduce this issue

在使用triple协议进行调用时,当请求/响应体序列化后长度超过128,会导致序列化失败

LengthFieldStreamingDecoder#bytesToInt方法先进行了移位才转换为int,导致负数情况下解析int错误

   protected static int bytesToInt(byte[] bytes) {
        return (bytes[0] << 24) & 0xFF | (bytes[1] << 16) & 0xFF | (bytes[2] << 8) & 0xFF | (bytes[3]) & 0xFF;
    }

测试代码

 public static void main(String[] args) {
        int intValue = 387; // 示例 int 值
        byte[] byteArray = new byte[4];
        byteArray[0] = (byte) (intValue >> 24); // 取 int 值的第一个字节
        byteArray[1] = (byte) (intValue >> 16); // 取 int 值的第二个字节
        byteArray[2] = (byte) (intValue >> 8);  // 取 int 值的第三个字节
        byteArray[3] = (byte) intValue;         // 取 int 值的第四个字节
        System.out.println(bytesToInt(byteArray) == intValue); // false 
    }

Pls. provide [GitHub address] to reproduce this issue.

Expected Behavior

true

Actual Behavior

false

If there is an exception, please attach the exception trace:

Just put your stack trace here!

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedEverything needs help from contributorstype/bugBugs to being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions