-
Notifications
You must be signed in to change notification settings - Fork 973
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
Wrong cast in StringCodec may lead to IndexOutOfBoundsException #1367
Comments
Moreover, I would really appreciate to have this included in an upcoming 5.3.x release (obviously if you accept it as a bug and agree with the fix). Workaround is to implement our own StringCodec (extending the original one) |
Good catch. In fact, we have multiple length calculations. Do you want to submit a pull request that fixes the issue and pulls calculation into a single place? |
@mp911de sure. Hopefully, it would be ready by tomorrow for review |
@mp911de done. I didn't follow the same approach for |
Bug Report
Current Behavior
Consider the following:
In
StringCodec#encodeAndAllocateBuffer
the byte buffer size is allocated using the method intotal_1
above. However, inByteBufUtil.writeUtf8(target, str)
ofStringCodec#encode
which subsequently callsByteBufUtil#utf8MaxBytes
, the Netty buffer is allocated with something more similar tototal_2
above.In such cases the exception thrown is as follows:
Environment
Possible Solution
I believe that the following line in
StringCodec#encodeAndAllocateBuffer
:should change to
similar handling may apply to
StringCodec#encode
where the line:should change to:
The text was updated successfully, but these errors were encountered: