Browse Source

Ignore ZIP extra fields that don't contain the recommended header+length structure - this is what unzip does as well. PR 42940

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@739300 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
e73a7f649f
7 changed files with 18 additions and 8 deletions
  1. +4
    -0
      WHATSNEW
  2. +0
    -4
      src/main/org/apache/tools/zip/ExtraFieldUtils.java
  3. +1
    -1
      src/main/org/apache/tools/zip/ZipEntry.java
  4. +1
    -1
      src/main/org/apache/tools/zip/ZipExtraField.java
  5. +10
    -0
      src/tests/antunit/taskdefs/unzip-test.xml
  6. BIN
      src/tests/antunit/taskdefs/zip/Bugzilla-46559.zip
  7. +2
    -2
      src/tests/junit/org/apache/tools/zip/ExtraFieldUtilsTest.java

+ 4
- 0
WHATSNEW View File

@@ -670,6 +670,10 @@ Other changes:
processor. processor.
Bugzilla Issue 46612. Bugzilla Issue 46612.


* the ZIP library will now ignore ZIP extra fields that don't specify
a size.
Bugzilla Report 42940.

Changes from Ant 1.7.0 TO Ant 1.7.1 Changes from Ant 1.7.0 TO Ant 1.7.1
============================================= =============================================




+ 0
- 4
src/main/org/apache/tools/zip/ExtraFieldUtils.java View File

@@ -117,10 +117,6 @@ public class ExtraFieldUtils {
} }
start += (length + WORD); start += (length + WORD);
} }
if (start != data.length) { // array not exhausted
throw new ZipException("data starting at " + start
+ " is in unknown format");
}


ZipExtraField[] result = new ZipExtraField[v.size()]; ZipExtraField[] result = new ZipExtraField[v.size()];
return (ZipExtraField[]) v.toArray(result); return (ZipExtraField[]) v.toArray(result);


+ 1
- 1
src/main/org/apache/tools/zip/ZipEntry.java View File

@@ -252,7 +252,7 @@ public class ZipEntry extends java.util.zip.ZipEntry implements Cloneable {
try { try {
setExtraFields(ExtraFieldUtils.parse(extra)); setExtraFields(ExtraFieldUtils.parse(extra));
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e.getMessage());
throw new RuntimeException(e.getMessage(), e);
} }
} }




+ 1
- 1
src/main/org/apache/tools/zip/ZipExtraField.java View File

@@ -64,7 +64,7 @@ public interface ZipExtraField {
byte[] getLocalFileDataData(); byte[] getLocalFileDataData();


/** /**
* The actual data to put central directory - without Header-ID or
* The actual data to put into central directory - without Header-ID or
* length specifier. * length specifier.
* @return the data * @return the data
* @since 1.1 * @since 1.1


+ 10
- 0
src/tests/antunit/taskdefs/unzip-test.xml View File

@@ -44,6 +44,16 @@
<au:assertFileExists file="${output}/foo/file"/> <au:assertFileExists file="${output}/foo/file"/>
</target> </target>


<target name="testTwoByteExtraFieldInLFH"
description="https://issues.apache.org/bugzilla/show_bug.cgi?id=42940"
>
<mkdir dir="${input}"/>
<mkdir dir="${output}"/>
<copy file="zip/Bugzilla-42940.zip" tofile="${input}/test.zip"/>
<unzip src="${input}/test.zip" dest="${output}"/>
<au:assertFileExists file="${output}/META-INF/MANIFEST.MF"/>
</target>

<target name="testArchiveIsClosedForInvalidZips" <target name="testArchiveIsClosedForInvalidZips"
description="https://issues.apache.org/bugzilla/show_bug.cgi?id=46559" description="https://issues.apache.org/bugzilla/show_bug.cgi?id=46559"
> >


BIN
src/tests/antunit/taskdefs/zip/Bugzilla-46559.zip View File


+ 2
- 2
src/tests/junit/org/apache/tools/zip/ExtraFieldUtilsTest.java View File

@@ -40,7 +40,7 @@ public class ExtraFieldUtilsTest extends TestCase implements UnixStat {
a.setDirectory(true); a.setDirectory(true);
dummy = new UnrecognizedExtraField(); dummy = new UnrecognizedExtraField();
dummy.setHeaderId(new ZipShort(1)); dummy.setHeaderId(new ZipShort(1));
dummy.setLocalFileDataData(new byte[0]);
dummy.setLocalFileDataData(new byte[] {0});
dummy.setCentralDirectoryData(new byte[] {0}); dummy.setCentralDirectoryData(new byte[] {0});


aLocal = a.getLocalFileDataData(); aLocal = a.getLocalFileDataData();
@@ -68,7 +68,7 @@ public class ExtraFieldUtilsTest extends TestCase implements UnixStat {
assertEquals("mode field 1", 040755, assertEquals("mode field 1", 040755,
((AsiExtraField) ze[0]).getMode()); ((AsiExtraField) ze[0]).getMode());
assertTrue("type field 2", ze[1] instanceof UnrecognizedExtraField); assertTrue("type field 2", ze[1] instanceof UnrecognizedExtraField);
assertEquals("data length field 2", 0,
assertEquals("data length field 2", 1,
ze[1].getLocalFileDataLength().getValue()); ze[1].getLocalFileDataLength().getValue());


byte[] data2 = new byte[data.length-1]; byte[] data2 = new byte[data.length-1];


Loading…
Cancel
Save