Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
halo
libcore
Commits
429f8329
Commit
429f8329
authored
11 years ago
by
Kenny Root
Committed by
Android (Google) Code Review
11 years ago
Browse files
Options
Download
Plain Diff
Merge "Fix extra and comment ordering in ZipEntry reading" into klp-dev
parents
b2bfa2d4
613ebea3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
5 deletions
+28
-5
luni/src/main/java/java/util/zip/ZipEntry.java
luni/src/main/java/java/util/zip/ZipEntry.java
+5
-5
luni/src/test/java/libcore/java/util/zip/ZipEntryTest.java
luni/src/test/java/libcore/java/util/zip/ZipEntryTest.java
+23
-0
No files found.
luni/src/main/java/java/util/zip/ZipEntry.java
View file @
429f8329
...
...
@@ -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
)
{
...
...
This diff is collapsed.
Click to expand it.
luni/src/test/java/libcore/java/util/zip/ZipEntryTest.java
View file @
429f8329
...
...
@@ -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
();
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment