ayushtkn commented on code in PR #537:
URL: https://github.com/apache/tez/pull/537#discussion_r4685580059


##########
tez-common/src/main/java/org/apache/tez/dag/utils/RelocalizationUtils.java:
##########
@@ -58,13 +59,43 @@ public static void addUrlsToClassPath(List<URL> urls) {
     ReflectionUtils.addResourcesToSystemClassLoader(urls);
   }
 
+  /** Validate all names up front, so callers can reject before mutating 
state. */
+  public static void validateDestNames(Collection<String> destNames) {
+    if (destNames == null) {
+      return;
+    }
+    for (String destName : destNames) {
+      validateDestName(destName);
+    }
+  }
+
   private static Path downloadResource(String destName, URI uri, Configuration 
conf, String destDir)
       throws IOException {
+    validateDestName(destName);
     FileSystem fs = FileSystem.get(uri, conf);
     Path cwd = new Path(destDir);
     Path dFile = new Path(cwd, destName);
     Path srcPath = new Path(uri);
     fs.copyToLocalFile(srcPath, dFile);
     return dFile.makeQualified(FileSystem.getLocal(conf).getUri(), cwd);
   }
+
+  static void validateDestName(String destName) {
+    if (destName == null || destName.isEmpty()) {
+      throw new IllegalArgumentException("Resource name must not be empty");
+    }
+    if (destName.indexOf('/') >= 0 || destName.indexOf('\\') >= 0
+        || destName.indexOf('\0') >= 0) {
+      throw new IllegalArgumentException(
+          "Resource name must not contain path separators: " + destName);
+    }
+    if (destName.equals(".") || destName.equals("..")) {
+      throw new IllegalArgumentException(
+          "Resource name must not be a parent-directory reference: " + 
destName);
+    }
+    if (new Path(destName).isAbsolute()) {
+      throw new IllegalArgumentException(
+          "Resource name must not be absolute: " + destName);
+    }

Review Comment:
   Can be dropped once `:` is rejected. Leading `/` and `\` are already covered 
by the separator check, and drive-absolute forms by :. This `new 
Path(destName)` call is also what made the check platform-dependent.



##########
tez-common/src/main/java/org/apache/tez/dag/utils/RelocalizationUtils.java:
##########
@@ -58,13 +59,43 @@ public static void addUrlsToClassPath(List<URL> urls) {
     ReflectionUtils.addResourcesToSystemClassLoader(urls);
   }
 
+  /** Validate all names up front, so callers can reject before mutating 
state. */
+  public static void validateDestNames(Collection<String> destNames) {
+    if (destNames == null) {
+      return;
+    }
+    for (String destName : destNames) {
+      validateDestName(destName);
+    }
+  }
+
   private static Path downloadResource(String destName, URI uri, Configuration 
conf, String destDir)
       throws IOException {
+    validateDestName(destName);
     FileSystem fs = FileSystem.get(uri, conf);
     Path cwd = new Path(destDir);
     Path dFile = new Path(cwd, destName);
     Path srcPath = new Path(uri);
     fs.copyToLocalFile(srcPath, dFile);
     return dFile.makeQualified(FileSystem.getLocal(conf).getUri(), cwd);
   }
+
+  static void validateDestName(String destName) {
+    if (destName == null || destName.isEmpty()) {
+      throw new IllegalArgumentException("Resource name must not be empty");
+    }
+    if (destName.indexOf('/') >= 0 || destName.indexOf('\\') >= 0
+        || destName.indexOf('\0') >= 0) {
+      throw new IllegalArgumentException(
+          "Resource name must not contain path separators: " + destName);
+    }

Review Comment:
   I think we also need to reject : here (destName.indexOf(':') >= 0) and use a 
single "illegal characters" message. 
   Opaque forms like `file:..` and `C:evil.jar` should be rejected explicitly. 
Right now they are rejected only because `new Path(destName`) throws. On 
`Windows` `(Path.WINDOWS)`, `new Path("C:evil.jar")` doesn't throw and 
i`sAbsolute()` is `false`, so that name would pass.
   
   



##########
tez-dag/src/main/java/org/apache/tez/dag/app/DAGAppMaster.java:
##########
@@ -1348,6 +1348,15 @@ public Void run() throws Exception {
 
   public String submitDAGToAppMaster(DAGPlan dagPlan,
       Map<String, LocalResource> additionalResources) throws TezException {
+    // Validate before startDAGExecution mutates currentDAG and amResources:
+    // a later failure would leave the session stuck "already running a DAG".
+    if (additionalResources != null) {
+      try {
+        RelocalizationUtils.validateDestNames(additionalResources.keySet());
+      } catch (IllegalArgumentException e) {
+        throw new TezException(e);
+      }
+    }

Review Comment:
   Could we add a test that a rejected submission leaves currentDAG and 
amResources untouched? That is the main claim in the comment above this block.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to