Skip to content

Commit b8d37ba

Browse files
jisedlacthurka
authored andcommitted
Utils.java, line 409 (Path Manipulation: Zip Entry Overwrite) - Fortify
1 parent 7256ba9 commit b8d37ba

File tree

1 file changed

+9
-2
lines changed
  • visualvm/core/src/com/sun/tools/visualvm/core/datasupport

1 file changed

+9
-2
lines changed

visualvm/core/src/com/sun/tools/visualvm/core/datasupport/Utils.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,17 +396,24 @@ public static File extractArchive(File archive, File destination) {
396396
ZipFile zipFile = null;
397397

398398
try {
399+
String destinationPath = directory.getCanonicalPath();
399400
prepareDirectory(directory);
400401

401402
zipFile = new ZipFile(archive);
402403
Enumeration<? extends ZipEntry> entries = zipFile.entries();
403404
while (entries.hasMoreElements()) {
404405
ZipEntry entry = entries.nextElement();
406+
File entryFile = new File(directory, entry.getName());
407+
408+
String entryFilePath = entryFile.getCanonicalPath();
409+
if (!entryFilePath.startsWith(destinationPath))
410+
throw new IllegalStateException("Archive entry outside of destination directory: " + entryFilePath); // NOI18N
411+
405412
FileOutputStream fos = null;
406413
InputStream is = null;
407414
try {
408415
is = zipFile.getInputStream(entry);
409-
fos = new FileOutputStream(new File(directory, entry.getName()));
416+
fos = new FileOutputStream(entryFile);
410417
int bytes;
411418
byte[] packet = new byte[COPY_PACKET_SIZE];
412419
while ((bytes = is.read(packet, 0, COPY_PACKET_SIZE)) != -1) fos.write(packet, 0, bytes);
@@ -491,5 +498,5 @@ private static byte[] imageToBytes(Image image, String format) {
491498

492499
return outputStream.toByteArray();
493500
}
494-
501+
495502
}

0 commit comments

Comments
 (0)