From 354d502fe161cde3c1e0cdb2a26eefd3a8a46a6f Mon Sep 17 00:00:00 2001 From: Andriy Plokhotnyuk Date: Tue, 18 Sep 2018 13:03:03 +0200 Subject: [PATCH] Mitigation of Play-JSON DoS https://github.com/playframework/play-json/issues/180 --- .../macros/ArrayOfZonedDateTimesBenchmark.scala | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/jsoniter-scala-benchmark/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/macros/ArrayOfZonedDateTimesBenchmark.scala b/jsoniter-scala-benchmark/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/macros/ArrayOfZonedDateTimesBenchmark.scala index afa645c1a..685cc7eac 100644 --- a/jsoniter-scala-benchmark/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/macros/ArrayOfZonedDateTimesBenchmark.scala +++ b/jsoniter-scala-benchmark/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/macros/ArrayOfZonedDateTimesBenchmark.scala @@ -13,10 +13,11 @@ import com.github.plokhotnyuk.jsoniter_scala.macros.UPickleReaderWriters._ import io.circe.parser._ import io.circe.syntax._ import org.openjdk.jmh.annotations.{Benchmark, Param, Setup} -import play.api.libs.json.Json +import play.api.libs.json._ import upickle.default._ import scala.collection.JavaConverters._ +import scala.util.Try class ArrayOfZonedDateTimesBenchmark extends CommonParams { val zoneIds: Array[ZoneId] = ZoneId.getAvailableZoneIds.asScala.map(ZoneId.of).toArray @@ -46,6 +47,10 @@ class ArrayOfZonedDateTimesBenchmark extends CommonParams { preallocatedBuf = new Array[Byte](jsonBytes.length + preallocatedOff + 100/*to avoid possible out of bounds error*/) } + implicit val zonedDateTimeArrayFormat: Format[ZonedDateTime] = Format( + Reads(js => Try(JsSuccess(ZonedDateTime.parse(js.as[JsString].value))).getOrElse(JsError.apply)), + Writes(v => JsString(v.toString))) + @Benchmark def readAVSystemGenCodec(): Array[ZonedDateTime] = JsonStringInput.read[Array[ZonedDateTime]](new String(jsonBytes, UTF_8))