Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -281,16 +281,19 @@ private[http] trait HttpMessageParser[Output >: MessageOutput <: ParserOutput] {
if (chunkCount >= settings.maxChunkCount)
failEntityStream(
s"HTTP chunk count exceeds the configured limit of ${settings.maxChunkCount} chunks")
val chunkBodyEnd = cursor + chunkSize
def result(terminatorLen: Int) = {
emit(EntityChunk(HttpEntity.Chunk(input.slice(cursor, chunkBodyEnd).compact, extension)))
Trampoline(_ =>
parseChunk(input, chunkBodyEnd + terminatorLen, isLastMessage, totalBytesRead + chunkSize, chunkCount + 1))
}
byteAt(input, chunkBodyEnd) match {
case CR_BYTE if byteAt(input, chunkBodyEnd + 1) == LF_BYTE => result(2)
case LF_BYTE => result(1)
case x => failEntityStream("Illegal chunk termination")
else {
val chunkBodyEnd = cursor + chunkSize
def result(terminatorLen: Int) = {
emit(EntityChunk(HttpEntity.Chunk(input.slice(cursor, chunkBodyEnd).compact, extension)))
Trampoline(_ =>
parseChunk(input, chunkBodyEnd + terminatorLen, isLastMessage, totalBytesRead + chunkSize,
chunkCount + 1))
}
byteAt(input, chunkBodyEnd) match {
case CR_BYTE if byteAt(input, chunkBodyEnd + 1) == LF_BYTE => result(2)
case LF_BYTE => result(1)
case x => failEntityStream("Illegal chunk termination")
}
}
} else parseTrailer(extension, cursor)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,29 @@ abstract class RequestParserSpec(mode: String, newLine: String) extends AnyFreeS
closeAfterResponseCompletion shouldEqual Seq(false)
}

"stop parsing a request that has more chunks than the configured limit" in new Test {
override protected def parserSettings: ParserSettings = super.parserSettings.withMaxChunkCount(2)

val input = prep(start +
"""1
|a
|1
|b
|1
|c
|0
|
|""")
// collect the raw parser output: nothing must be emitted after the error, in particular no further chunk
val outputs =
Source.single(SessionBytes(TLSPlacebo.dummySession, ByteString(input)))
.via(newParser).runWith(Sink.seq).awaitResult(awaitAtMost)

outputs.collect { case EntityChunk(chunk) => chunk.data.utf8String } shouldEqual Seq("a", "b")
outputs.last shouldEqual EntityStreamError(
ErrorInfo("HTTP chunk count exceeds the configured limit of 2 chunks"))
}

"don't overflow the stack for large buffers of chunks" in new Test {
override val awaitAtMost = 10000.millis.dilated

Expand Down