Skip to content

IOUtils类存在问题 #27

Description

@sd4324530

类:com.yuqi.protocol.utils.IOUtils
方法:writeLengthEncodedInteger , writeInteger
问题:

writeLengthEncodedInteger方法里的这2个分支的条件

else if (s < 2 << 16) {
            IOUtils.writeByte((byte) MYSQL_TYPE_BLOB, byteBuf);
            IOUtils.writeInteger(s, byteBuf, 2);
        } else if (s < 2 << 24) {
            IOUtils.writeByte((byte) MYSQL_TYPE_VAR_STRING, byteBuf);
            IOUtils.writeInteger(s, byteBuf, 3);
        }

与writeInteger方法里的校验条件不匹配,数据范围不能完全覆盖,传入后会报错过大

if (length == 3 && (s > (1 << 23) || s < -(1 << 24))) {
            throw new RuntimeException("s is granter than 2^23 or less then -2^23");
        }

        if (length == 2 && (s > Short.MAX_VALUE || s < Short.MIN_VALUE)) {
            throw new RuntimeException("Number exceed short value: " + s);
        }

2 << 16 = 131072
但是进入writeInteger后,超过Short.MAX_VALUE就会报错

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions