File tree Expand file tree Collapse file tree 2 files changed +43
-2
lines changed
main/scala/org/apache/spark/util
test/scala/org/apache/spark/util Expand file tree Collapse file tree 2 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -919,8 +919,18 @@ private[spark] class JsonProtocol(sparkConf: SparkConf) extends JsonUtils {
919
919
case `stageExecutorMetrics` => stageExecutorMetricsFromJson(json)
920
920
case `blockUpdate` => blockUpdateFromJson(json)
921
921
case `resourceProfileAdded` => resourceProfileAddedFromJson(json)
922
- case other => mapper.readValue(json.toString, Utils .classForName(other))
923
- .asInstanceOf [SparkListenerEvent ]
922
+ case other =>
923
+ if (other.startsWith(" org.apache.spark" )) {
924
+ val otherClass = Utils .classForName(other)
925
+ if (classOf [SparkListenerEvent ].isAssignableFrom(otherClass)) {
926
+ mapper.readValue(json.toString, otherClass)
927
+ .asInstanceOf [SparkListenerEvent ]
928
+ } else {
929
+ throw new SparkException (s " Unknown event type: $other" )
930
+ }
931
+ } else {
932
+ throw new SparkException (s " Unknown event type: $other" )
933
+ }
924
934
}
925
935
}
926
936
Original file line number Diff line number Diff line change @@ -1022,6 +1022,37 @@ class jsonProtocolSuite extends SparkFunSuite {
1022
1022
" String value length (10000) exceeds the maximum allowed"
1023
1023
))
1024
1024
}
1025
+
1026
+ test(" SPARK-52381: only read Spark classes" ) {
1027
+ val unknownJson =
1028
+ """ {
1029
+ | "Event" : "com.example.UnknownEvent",
1030
+ | "foo" : "foo"
1031
+ |}""" .stripMargin
1032
+ try {
1033
+ jsonProtocol.sparkEventFromJson(unknownJson)
1034
+ fail(" Expected SparkException for unknown event type" )
1035
+ } catch {
1036
+ case e : SparkException =>
1037
+ assert(e.getMessage.startsWith(" Unknown event type" ))
1038
+ }
1039
+ }
1040
+
1041
+ test(" SPARK-52381: only read classes that extend SparkListenerEvent" ) {
1042
+ val unknownJson =
1043
+ """ {
1044
+ | "Event" : "org.apache.spark.SparkException",
1045
+ | "foo" : "foo"
1046
+ |}""" .stripMargin
1047
+ try {
1048
+ jsonProtocol.sparkEventFromJson(unknownJson)
1049
+ fail(" Expected SparkException for unknown event type" )
1050
+ } catch {
1051
+ case e : SparkException =>
1052
+ assert(e.getMessage.startsWith(" Unknown event type" ))
1053
+ }
1054
+ }
1055
+
1025
1056
}
1026
1057
1027
1058
You can’t perform that action at this time.
0 commit comments