Copilot commented on code in PR #139:
URL: https://github.com/apache/dubbo-getty/pull/139#discussion_r3709444667
##########
session.go:
##########
@@ -721,6 +721,18 @@ func (s *session) handleTCPPackage() error {
return perrors.WithStack(err)
}
+func udpReadBufferLen(maxMsgLen int32) int {
+ maxBufLen := maxReadBufLen
+ if maxMsgLen > 0 {
+ maxMsgLen := int(maxMsgLen)
+ maxBufLen = maxMsgLen + maxReadBufLen
+ if maxMsgLen<<1 < maxBufLen {
+ maxBufLen = maxMsgLen << 1
+ }
+ }
+ return maxBufLen
+}
Review Comment:
`udpReadBufferLen` shadows the `maxMsgLen` parameter (`maxMsgLen :=
int(maxMsgLen)`) and performs `+` / `<<` operations in `int`, which can
overflow on 32-bit platforms or with large configured max message sizes. An
overflow here could yield a negative/too-small buffer length and cause panics
or truncated reads.
Consider computing in `int64`, avoid the shadowed name, and clamp the final
result to `MaxInt` before converting back to `int`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]