Copilot commented on code in PR #19818:
URL: https://github.com/apache/druid/pull/19818#discussion_r3720859088
##########
multi-stage-query/src/main/java/org/apache/druid/msq/exec/ControllerImpl.java:
##########
@@ -976,15 +976,15 @@ public void workerWarning(List<MSQErrorReport>
errorReports)
{
// This check safeguards that the controller doesn't run out of memory.
Workers apply their own limiting to
// protect their own memory, and to conserve worker -> controller
bandwidth.
- long numReportsToAddCheck = Math.min(
+ final int numReportsToAddCheck = Math.min(
errorReports.size(),
- Limits.MAX_WORKERS * Limits.MAX_VERBOSE_WARNINGS -
workerWarnings.size()
+ Math.toIntExact(Limits.MAX_WORKERS * Limits.MAX_VERBOSE_WARNINGS -
workerWarnings.size())
);
if (numReportsToAddCheck > 0) {
synchronized (workerWarnings) {
- long numReportsToAdd = Math.min(
+ final int numReportsToAdd = Math.min(
errorReports.size(),
- Limits.MAX_WORKERS * Limits.MAX_VERBOSE_WARNINGS -
workerWarnings.size()
+ Math.toIntExact(Limits.MAX_WORKERS * Limits.MAX_VERBOSE_WARNINGS -
workerWarnings.size())
);
Review Comment:
`Limits.MAX_WORKERS * Limits.MAX_VERBOSE_WARNINGS` will be evaluated using
`int` arithmetic if those constants are `int`, potentially overflowing before
the result is widened and passed to `Math.toIntExact`. This can cause incorrect
limiting (including allowing too many warnings or prematurely stopping
additions). Compute the limit using `long` arithmetic (or `Math.multiplyExact`
on `long`s) before subtracting `workerWarnings.size()`, then clamp/convert 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]