diff options
-rw-r--r-- | luni/src/main/java/java/util/zip/ZipEntry.java | 10 | ||||
-rw-r--r-- | luni/src/test/java/libcore/java/util/zip/ZipEntryTest.java | 23 |
2 files changed, 28 insertions, 5 deletions
diff --git a/luni/src/main/java/java/util/zip/ZipEntry.java b/luni/src/main/java/java/util/zip/ZipEntry.java index ee68b66..e4146bd 100644 --- a/luni/src/main/java/java/util/zip/ZipEntry.java +++ b/luni/src/main/java/java/util/zip/ZipEntry.java @@ -385,6 +385,11 @@ public class ZipEntry implements ZipConstants, Cloneable { Streams.readFully(in, nameBytes, 0, nameBytes.length); name = new String(nameBytes, 0, nameBytes.length, StandardCharsets.UTF_8); + if (extraLength > 0) { + extra = new byte[extraLength]; + Streams.readFully(in, extra, 0, extraLength); + } + // The RI has always assumed UTF-8. (If GPBF_UTF8_FLAG isn't set, the encoding is // actually IBM-437.) if (commentByteCount > 0) { @@ -392,10 +397,5 @@ public class ZipEntry implements ZipConstants, Cloneable { Streams.readFully(in, commentBytes, 0, commentByteCount); comment = new String(commentBytes, 0, commentBytes.length, StandardCharsets.UTF_8); } - - if (extraLength > 0) { - extra = new byte[extraLength]; - Streams.readFully(in, extra, 0, extraLength); - } } } diff --git a/luni/src/test/java/libcore/java/util/zip/ZipEntryTest.java b/luni/src/test/java/libcore/java/util/zip/ZipEntryTest.java index 0845b32..550ddfb 100644 --- a/luni/src/test/java/libcore/java/util/zip/ZipEntryTest.java +++ b/luni/src/test/java/libcore/java/util/zip/ZipEntryTest.java @@ -169,4 +169,27 @@ public class ZipEntryTest extends junit.framework.TestCase { assertEquals(maxLengthComment, zipFile.getEntry("x").getComment()); zipFile.close(); } + + public void testCommentAndExtraInSameOrder() throws Exception { + String comment = makeString(17, "z"); + byte[] extra = makeString(11, "a").getBytes(); + + File f = createTemporaryZipFile(); + ZipOutputStream out = createZipOutputStream(f); + ZipEntry ze = new ZipEntry("x"); + ze.setExtra(extra); + ze.setComment(comment); + out.putNextEntry(ze); + out.closeEntry(); + out.close(); + + // Read it back and make sure comments and extra are in the right order + ZipFile zipFile = new ZipFile(f); + try { + assertEquals(comment, zipFile.getEntry("x").getComment()); + assertTrue(Arrays.equals(extra, zipFile.getEntry("x").getExtra())); + } finally { + zipFile.close(); + } + } } |