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
rockchip_libcore
Commits
c8321962
Commit
c8321962
authored
12 years ago
by
Geremy Condra
Browse files
Options
Download
Email Patches
Plain Diff
Remove support for duplicate file entries.
Bug: 8219321 Change-Id: I4ac47f8facf13afa45799a0d5e20202a0ef5f0c6
parent
b5c84e12
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
1 deletion
+69
-1
luni/src/main/java/java/util/zip/ZipFile.java
luni/src/main/java/java/util/zip/ZipFile.java
+4
-1
luni/src/test/java/libcore/java/util/zip/ZipFileTest.java
luni/src/test/java/libcore/java/util/zip/ZipFileTest.java
+65
-0
No files found.
luni/src/main/java/java/util/zip/ZipFile.java
View file @
c8321962
...
...
@@ -363,7 +363,10 @@ public class ZipFile implements ZipConstants {
byte
[]
hdrBuf
=
new
byte
[
CENHDR
];
// Reuse the same buffer for each entry.
for
(
int
i
=
0
;
i
<
numEntries
;
++
i
)
{
ZipEntry
newEntry
=
new
ZipEntry
(
hdrBuf
,
bin
);
mEntries
.
put
(
newEntry
.
getName
(),
newEntry
);
String
entryName
=
newEntry
.
getName
();
if
(
mEntries
.
put
(
entryName
,
newEntry
)
!=
null
)
{
throw
new
ZipException
(
"Duplicate entry name: "
+
entryName
);
}
}
}
...
...
This diff is collapsed.
Click to expand it.
luni/src/test/java/libcore/java/util/zip/ZipFileTest.java
View file @
c8321962
...
...
@@ -16,9 +16,12 @@
package
libcore.java.util.zip
;
import
java.io.BufferedOutputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.Enumeration
;
...
...
@@ -28,6 +31,7 @@ import java.util.zip.ZipFile;
import
java.util.zip.ZipInputStream
;
import
java.util.zip.ZipOutputStream
;
import
junit.framework.TestCase
;
import
libcore.io.IoUtils
;
public
final
class
ZipFileTest
extends
TestCase
{
...
...
@@ -51,6 +55,67 @@ public final class ZipFileTest extends TestCase {
}
}
private
static
void
replaceBytes
(
byte
[]
original
,
byte
[]
replacement
,
byte
[]
buffer
)
{
// Gotcha here: original and replacement must be the same length
assertEquals
(
original
.
length
,
replacement
.
length
);
boolean
found
;
for
(
int
i
=
0
;
i
<
buffer
.
length
-
original
.
length
;
i
++)
{
found
=
false
;
if
(
buffer
[
i
]
==
original
[
0
])
{
found
=
true
;
for
(
int
j
=
0
;
j
<
original
.
length
;
j
++)
{
if
(
buffer
[
i
+
j
]
!=
original
[
j
])
{
found
=
false
;
break
;
}
}
}
if
(
found
)
{
for
(
int
j
=
0
;
j
<
original
.
length
;
j
++)
{
buffer
[
i
+
j
]
=
replacement
[
j
];
}
}
}
}
/**
* Make sure we don't fail silently for duplicate entries.
* b/8219321
*/
public
void
testDuplicateEntries
()
throws
IOException
{
String
entryName
=
"test_file_name1"
;
String
tmpName
=
"test_file_name2"
;
// create the template data
ByteArrayOutputStream
bytesOut
=
new
ByteArrayOutputStream
();
ZipOutputStream
out
=
new
ZipOutputStream
(
bytesOut
);
ZipEntry
ze1
=
new
ZipEntry
(
tmpName
);
out
.
putNextEntry
(
ze1
);
out
.
closeEntry
();
ZipEntry
ze2
=
new
ZipEntry
(
entryName
);
out
.
putNextEntry
(
ze2
);
out
.
closeEntry
();
out
.
close
();
// replace the bytes we don't like
byte
[]
buf
=
bytesOut
.
toByteArray
();
replaceBytes
(
tmpName
.
getBytes
(),
entryName
.
getBytes
(),
buf
);
// write the result to a file
File
badZip
=
File
.
createTempFile
(
"badzip"
,
"zip"
);
badZip
.
deleteOnExit
();
FileOutputStream
outstream
=
new
FileOutputStream
(
badZip
);
outstream
.
write
(
buf
);
outstream
.
close
();
// see if we can still handle it
try
{
ZipFile
bad
=
new
ZipFile
(
badZip
);
fail
();
}
catch
(
ZipException
expected
)
{
}
}
public
void
testInflatingStreamsRequiringZipRefill
()
throws
IOException
{
int
originalSize
=
1024
*
1024
;
byte
[]
readBuffer
=
new
byte
[
8192
];
...
...
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