reef-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (REEF-2019) Enforce uncompressed files are within the current working directory in EvaluatorShim
Date Sun, 03 Jun 2018 15:35:00 GMT

    [ https://issues.apache.org/jira/browse/REEF-2019?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16499453#comment-16499453
] 

ASF GitHub Bot commented on REEF-2019:
--------------------------------------

markusweimer closed pull request #1463: [REEF-2019] Enforce uncompressed files are within
the current directory
URL: https://github.com/apache/reef/pull/1463
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/lang/java/reef-runtime-azbatch/src/main/java/org/apache/reef/runtime/azbatch/evaluator/EvaluatorShim.java
b/lang/java/reef-runtime-azbatch/src/main/java/org/apache/reef/runtime/azbatch/evaluator/EvaluatorShim.java
index 1579c266a1..361d65bf87 100644
--- a/lang/java/reef-runtime-azbatch/src/main/java/org/apache/reef/runtime/azbatch/evaluator/EvaluatorShim.java
+++ b/lang/java/reef-runtime-azbatch/src/main/java/org/apache/reef/runtime/azbatch/evaluator/EvaluatorShim.java
@@ -44,7 +44,7 @@
 import java.io.InputStream;
 import java.net.URI;
 import java.nio.file.Files;
-import java.nio.file.Paths;
+import java.nio.file.Path;
 import java.util.Arrays;
 import java.util.Enumeration;
 import java.util.List;
@@ -277,9 +277,14 @@ private File downloadFile(final String url) throws IOException, StorageException
   private void extractFiles(final File zipFile) throws IOException {
     try (ZipFile zipFileHandle = new ZipFile(zipFile)) {
       Enumeration<? extends ZipEntry> zipEntries = zipFileHandle.entries();
+      Path reefPath = this.reefFileNames.getREEFFolder().toPath();
       while (zipEntries.hasMoreElements()) {
         ZipEntry zipEntry = zipEntries.nextElement();
-        File file = new File(this.reefFileNames.getREEFFolderName() + '/' + zipEntry.getName());
+        Path destination = new File(this.reefFileNames.getREEFFolder(), zipEntry.getName()).toPath();
+        if (!destination.startsWith(reefPath)) {
+          throw new IOException("Trying to unzip a file outside of the destination folder:
" + destination);
+        }
+        File file = destination.toFile();
         if (file.exists()) {
           LOG.log(Level.INFO, "Skipping entry {0} because the file already exists.", zipEntry.getName());
         } else {
@@ -292,7 +297,7 @@ private void extractFiles(final File zipFile) throws IOException {
           } else {
             try (InputStream inputStream = zipFileHandle.getInputStream(zipEntry)) {
               LOG.log(Level.INFO, "Extracting {0}.", zipEntry.getName());
-              Files.copy(inputStream, Paths.get(this.reefFileNames.getREEFFolderName() +
'/' + zipEntry.getName()));
+              Files.copy(inputStream, destination);
               LOG.log(Level.INFO, "Extracting {0} completed.", zipEntry.getName());
             }
           }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Enforce uncompressed files are within the current working directory in EvaluatorShim
> ------------------------------------------------------------------------------------
>
>                 Key: REEF-2019
>                 URL: https://issues.apache.org/jira/browse/REEF-2019
>             Project: REEF
>          Issue Type: Bug
>          Components: REEF-Runtime-AZBatch
>            Reporter: Byung-Gon Chun
>            Assignee: Gyewon Lee
>            Priority: Major
>
> When compressed files are uncompressed, the files can be created outside the current
working directory in EvaluatorShim (L295). 
> [https://github.com/apache/reef/blob/561a336f2f0dda8f4a67a96179750a76167b038f/lang/java/reef-runtime-azbatch/src/main/java/org/apache/reef/runtime/azbatch/evaluator/EvaluatorShim.java#L295
> ]
> We will enforce that uncompressed files in EvaluatorShim are within the current working
directory. If not, an exception will be raised.
> [~markus.weimer] suggested the following fix.
> final Path reefPath = this.reefFileNames.getREEFFolder().toPath();
> ...
> final Path destination = new File(this.reefFileNames.getREEFFolder(),
> zipEntry.getName()).toPath();
> if(!destination.startsWith(reefPath)){
>   throw new IOException("Trying to unzip a file outside of the
> destination folder: " + destination);
> }
> Files.copy(inputStream, destination);
> Assigning this issue to [~gyewonlee].



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message