Commit 429f8329 authored by Kenny Root's avatar Kenny Root Committed by Android (Google) Code Review
Browse files

Merge "Fix extra and comment ordering in ZipEntry reading" into klp-dev

parents b2bfa2d4 613ebea3
......@@ -389,6 +389,11 @@ public class ZipEntry implements ZipConstants, Cloneable {
}
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) {
......@@ -396,11 +401,6 @@ 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);
}
}
private static boolean containsNulByte(byte[] bytes) {
......
......@@ -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();
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment