From e677c933d38129ca727bc1e9931c63e6dac963f4 Mon Sep 17 00:00:00 2001 From: Nepomuk Crhonek <105591323+Nepomuk5665@users.noreply.github.com> Date: Fri, 23 Jan 2026 13:19:55 +0100 Subject: [PATCH] Fix integer overflow in ForeachDetails interval comparator The intervalComparator method used (int)(i1.start - i2.start) which can overflow when the difference between two long values exceeds Integer.MAX_VALUE. For example, if i1.start = 3_000_000_000 and i2.start = 0, the result 3_000_000_000 overflows to a negative int value, causing incorrect sort order. This fix uses Long.compare() which correctly handles all long value ranges and is the standard pattern for comparing primitive long values. --- .../com/netflix/maestro/models/instance/ForeachDetails.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maestro-common/src/main/java/com/netflix/maestro/models/instance/ForeachDetails.java b/maestro-common/src/main/java/com/netflix/maestro/models/instance/ForeachDetails.java index 3a4b28b7..f3a13cc3 100644 --- a/maestro-common/src/main/java/com/netflix/maestro/models/instance/ForeachDetails.java +++ b/maestro-common/src/main/java/com/netflix/maestro/models/instance/ForeachDetails.java @@ -103,7 +103,7 @@ public Interval deserialize(JsonParser p, DeserializationContext ctxt) throws IO } private static int intervalComparator(Interval i1, Interval i2) { - return (int) (i1.start - i2.start); + return Long.compare(i1.start, i2.start); } /** Add one instance with its status into the pending buffer. */