davidradl commented on code in PR #28252:
URL: https://github.com/apache/flink/pull/28252#discussion_r3357402152


##########
flink-core/src/main/java/org/apache/flink/core/memory/DataOutputSerializer.java:
##########
@@ -333,26 +341,52 @@ private int getUTFBytesSize(int c) {
         }
     }
 
+    /**
+     * Computes the new buffer length for a {@link #resize(int)} call.
+     *
+     * <p>Uses {@code long} arithmetic so that doubling does not silently 
overflow once the current
+     * buffer length crosses {@code Integer.MAX_VALUE / 2}. When doubling 
would exceed {@link
+     * #MAX_ARRAY_SIZE}, the buffer jumps directly to the cap rather than 
growing by {@code
+     * minCapacityAdd} bytes at a time — the latter would degrade every 
subsequent resize into a
+     * full copy of a ~1–2 GB buffer.
+     *
+     * @throws IOException if the required size exceeds {@link 
#MAX_ARRAY_SIZE}.
+     */
+    @VisibleForTesting
+    static int computeNewBufferLength(int currentLength, int minCapacityAdd) 
throws IOException {
+        long requiredLen = (long) currentLength + minCapacityAdd;

Review Comment:
   I think we should check that these values are positive. I am not sure if 0 
for either value would not cause issues. 



-- 
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]

Reply via email to