Skip to content

Commit 098f83c

Browse files
sarutakAndrew Or
authored and
Andrew Or
committed
[SPARK-4075] [Deploy] Jar url validation is not enough for Jar file
In deploy.ClientArguments.isValidJarUrl, the url is checked as follows. def isValidJarUrl(s: String): Boolean = s.matches("(.+):(.+)jar") So, it allows like 'hdfs:file.jar' (no authority). Author: Kousuke Saruta <sarutak@oss.nttdata.co.jp> Closes apache#2925 from sarutak/uri-syntax-check-improvement and squashes the following commits: cf06173 [Kousuke Saruta] Improved URI syntax checking
1 parent 30ea286 commit 098f83c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

core/src/main/scala/org/apache/spark/deploy/ClientArguments.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.apache.spark.deploy
1919

20+
import java.net.{URI, URISyntaxException}
21+
2022
import scala.collection.mutable.ListBuffer
2123

2224
import org.apache.log4j.Level
@@ -114,5 +116,12 @@ private[spark] class ClientArguments(args: Array[String]) {
114116
}
115117

116118
object ClientArguments {
117-
def isValidJarUrl(s: String): Boolean = s.matches("(.+):(.+)jar")
119+
def isValidJarUrl(s: String): Boolean = {
120+
try {
121+
val uri = new URI(s)
122+
uri.getScheme != null && uri.getAuthority != null && s.endsWith("jar")
123+
} catch {
124+
case _: URISyntaxException => false
125+
}
126+
}
118127
}

core/src/test/scala/org/apache/spark/deploy/ClientSuite.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ class ClientSuite extends FunSuite with Matchers {
2929
ClientArguments.isValidJarUrl("hdfs://someHost:1234/foo") should be (false)
3030
ClientArguments.isValidJarUrl("/missing/a/protocol/jarfile.jar") should be (false)
3131
ClientArguments.isValidJarUrl("not-even-a-path.jar") should be (false)
32+
33+
// No authority
34+
ClientArguments.isValidJarUrl("hdfs:someHost:1234/jarfile.jar") should be (false)
35+
36+
// Invalid syntax
37+
ClientArguments.isValidJarUrl("hdfs:") should be (false)
3238
}
3339

3440
}

0 commit comments

Comments
 (0)