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

IOUtils类存在问题 #27

Open
sd4324530 opened this issue Jan 9, 2023 · 0 comments
Open

IOUtils类存在问题 #27

sd4324530 opened this issue Jan 9, 2023 · 0 comments

Comments

@sd4324530
Copy link

sd4324530 commented Jan 9, 2023

类: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就会报错

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant