From db634477397c4aa158a8c38ce288def3eb240e2b Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Sun, 3 Mar 2013 09:59:47 +0000 Subject: [PATCH] size comparator was vulnerable to integer overflows. PR 54623 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1452022 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 4 ++++ .../apache/tools/ant/types/resources/comparators/Size.java | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/WHATSNEW b/WHATSNEW index f548d2f6b..4ba97742d 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -77,6 +77,10 @@ Fixed bugs: * Base64Converter not properly handling bytes with MSB set (not masking byte to int conversion) Bugzilla Report 54460 + * The size resource comparator would return wrong results if file + sizes differed by more than 2 GB. + Bugzilla Report 54623 + Other changes: -------------- diff --git a/src/main/org/apache/tools/ant/types/resources/comparators/Size.java b/src/main/org/apache/tools/ant/types/resources/comparators/Size.java index d608a96a2..b94f250b1 100644 --- a/src/main/org/apache/tools/ant/types/resources/comparators/Size.java +++ b/src/main/org/apache/tools/ant/types/resources/comparators/Size.java @@ -32,7 +32,8 @@ public class Size extends ResourceComparator { * argument is less than, equal to, or greater than the second. */ protected int resourceCompare(Resource foo, Resource bar) { - return (int) (foo.getSize() - bar.getSize()); + long diff = foo.getSize() - bar.getSize(); + return diff > 0 ? 1 : (diff == 0 ? 0 : -1); } }