Skip to content

Commit

Permalink
Merge pull request #10753 from playframework/mergify/bp/2.8.x/pr-10741
Browse files Browse the repository at this point in the history
fix Int overflow in BodyParsers.anyContent(maxLength: Option[Long]) (bp #10741)
  • Loading branch information
mergify[bot] committed Mar 10, 2021
2 parents 2a43f63 + 6b608b2 commit fa07939
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import play.api.test._

class AnyContentBodyParserSpec extends PlaySpecification {
"The anyContent body parser" should {
def parse(method: String, contentType: Option[String], body: ByteString)(implicit app: Application) = {
def parse(method: String, contentType: Option[String], body: ByteString, maxLength: Option[Long] = None)(
implicit app: Application
) = {
implicit val mat = app.materializer
val parsers = app.injector.instanceOf[PlayBodyParsers]
val request = FakeRequest(method, "/x").withHeaders(contentType.map(CONTENT_TYPE -> _).toSeq: _*)
await(parsers.anyContent(request).run(Source.single(body)))
await(parsers.anyContent(maxLength).apply(request).run(Source.single(body)))
}

"parse text bodies for DELETE requests" in new WithApplication(_.globalApp(false)) {
Expand Down Expand Up @@ -66,5 +68,11 @@ class AnyContentBodyParserSpec extends PlaySpecification {
}
}
}

"accept greater than 2G bytes. not Int overflow" in new WithApplication(_.globalApp(false)) {
parse("POST", Some("text/plain"), ByteString("bar"), maxLength = Some(Int.MaxValue.toLong + 2L)) must beRight(
AnyContentAsText("bar")
)
}
}
}
2 changes: 1 addition & 1 deletion core/play/src/main/scala/play/api/mvc/BodyParsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ trait PlayBodyParsers extends BodyParserUtils {
def anyContent(maxLength: Option[Long]): BodyParser[AnyContent] = BodyParser("anyContent") { request =>
import Execution.Implicits.trampoline

def maxLengthOrDefault = maxLength.fold(DefaultMaxTextLength)(_.toInt)
def maxLengthOrDefault = maxLength.getOrElse(DefaultMaxTextLength)
def maxLengthOrDefaultLarge = maxLength.getOrElse(DefaultMaxDiskLength)
val contentType: Option[String] = request.contentType.map(_.toLowerCase(Locale.ENGLISH))
contentType match {
Expand Down

0 comments on commit fa07939

Please sign in to comment.