Copilot commented on code in PR #1520:
URL: https://github.com/apache/cloudberry/pull/1520#discussion_r2662378521
##########
contrib/interconnect/udp/ic_udpifc.c:
##########
@@ -3753,7 +3753,7 @@ SetupUDPIFCInterconnect(EState *estate)
Gp_interconnect_queue_depth == 4 &&
Gp_interconnect_snd_queue_depth == 2)
{
- int32 perQueue = Gp_interconnect_mem_size /
+ int32 perQueue = ((int64)Gp_interconnect_mem_size *
1024 * 1024) /
(Gp_max_packet_size * sliceNum);
Review Comment:
The denominator calculation `(Gp_max_packet_size * sliceNum)` can overflow
when both operands are large. Since `Gp_max_packet_size` is an `int` (max
65507) and `sliceNum` is an `int32`, their multiplication is performed as
integer arithmetic before being used in the division with `int64`. For example,
if `Gp_max_packet_size = 65507` and `sliceNum = 40000`, the product
(2,620,280,000) exceeds INT_MAX (2,147,483,647), causing integer overflow.
To prevent this, cast one of the operands in the denominator to `int64`
before the multiplication, similar to how the numerator is handled.
```suggestion
((int64) Gp_max_packet_size * sliceNum);
```
--
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]