diff --git a/WHATSNEW b/WHATSNEW index a55eed50f..1bc965607 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -325,6 +325,9 @@ Fixed bugs: * 's defaultexcludes attribute was ignored when an archive was updated. Bugzilla Report 33412. +* couldn't store files with size between 2GB and 4GB (the + upper limit set by the ZIP format itself). Bugzilla Report 33310. + Changes from Ant 1.6.1 to Ant 1.6.2 =================================== diff --git a/src/main/org/apache/tools/zip/ZipOutputStream.java b/src/main/org/apache/tools/zip/ZipOutputStream.java index c2d9926de..2db125136 100644 --- a/src/main/org/apache/tools/zip/ZipOutputStream.java +++ b/src/main/org/apache/tools/zip/ZipOutputStream.java @@ -336,8 +336,8 @@ public class ZipOutputStream extends FilterOutputStream { deflate(); } - entry.setSize(def.getTotalIn()); - entry.setComprSize(def.getTotalOut()); + entry.setSize(adjustToLong(def.getTotalIn())); + entry.setComprSize(adjustToLong(def.getTotalOut())); entry.setCrc(realCrc); def.reset(); @@ -877,4 +877,19 @@ public class ZipOutputStream extends FilterOutputStream { out.write(data, offset, length); } } + + /** + * Assumes a negative integer really is a positive integer that + * has wrapped around and re-creates the original value. + * + * @since 1.34 + */ + protected static long adjustToLong(int i) { + if (i < 0) { + return 2 * ((long) Integer.MAX_VALUE) + 2 + i; + } else { + return i; + } + } + } diff --git a/src/testcases/org/apache/tools/zip/ZipOutputStreamTest.java b/src/testcases/org/apache/tools/zip/ZipOutputStreamTest.java index fa92f858e..3fc45555a 100644 --- a/src/testcases/org/apache/tools/zip/ZipOutputStreamTest.java +++ b/src/testcases/org/apache/tools/zip/ZipOutputStreamTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2004 The Apache Software Foundation + * Copyright 2004-2005 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -66,4 +66,13 @@ public class ZipOutputStreamTest extends TestCase { assertEquals(test.getValue(), zl.getValue()); } + public void testAdjustToLong() { + assertEquals((long) Integer.MAX_VALUE, + ZipOutputStream.adjustToLong(Integer.MAX_VALUE)); + assertEquals(((long) Integer.MAX_VALUE) + 1, + ZipOutputStream.adjustToLong(Integer.MAX_VALUE + 1)); + assertEquals(2 * ((long) Integer.MAX_VALUE), + ZipOutputStream.adjustToLong(2 * Integer.MAX_VALUE)); + } + }