fix parsing of uneven stream bodies #1764
Conversation
//the chunk matches from the very beginning, | ||
//since currstate can never be greater than | ||
//(i + state). | ||
val middleChunked = i + state - currState > 0 |
jmcardon
Apr 3, 2018
•
Author
Member
Some background on this condition to help review:
state
is essentially a counter to the last index of a particular byte sequence seen. This is necessary since boundaries may be spread across chunks. I also denote carry
as a possible partial match on a boundary, which gets re-emitted if it happens that it wasn't, or ignored if it completed a boundary.
middleChunked
is simply the condition of whether the particular match, for example a boundary match, starts somewhere after the start of this chunk (index 0). If that is the case, then we know that the previous possible partial match on the boundary was a false positive and we can reemit it.
i - (currState - state) > 0
is essentially the condition we are after: This means if the amount of the value to match is equal to i
(which is the counter over the whole chunk until possibly completing the match), then clearly the match started at the beginning of the chunk, in which case we can ignore the previous carry
. If this condition is greater than 0, this means that this boundary match began somewhere in the midde, thus it is middleChunked
Some background on this condition to help review:
state
is essentially a counter to the last index of a particular byte sequence seen. This is necessary since boundaries may be spread across chunks. I also denote carry
as a possible partial match on a boundary, which gets re-emitted if it happens that it wasn't, or ignored if it completed a boundary.
middleChunked
is simply the condition of whether the particular match, for example a boundary match, starts somewhere after the start of this chunk (index 0). If that is the case, then we know that the previous possible partial match on the boundary was a false positive and we can reemit it.
i - (currState - state) > 0
is essentially the condition we are after: This means if the amount of the value to match is equal to i
(which is the counter over the whole chunk until possibly completing the match), then clearly the match started at the beginning of the chunk, in which case we can ignore the previous carry
. If this condition is greater than 0, this means that this boundary match began somewhere in the midde, thus it is middleChunked
@@ -274,7 +266,7 @@ object MultipartParser { | |||
c: Chunk[Byte] | |||
): (Int, Stream[F, Byte], Stream[F, Byte]) = { | |||
val ixx = i - currState | |||
if (middleChunked || state == 0) { |
jmcardon
Apr 3, 2018
Author
Member
state == 0 condition was removed because it is not longer necessary: this case will be picked up as a middleChunked
case, now always.
state == 0 condition was removed because it is not longer necessary: this case will be picked up as a middleChunked
case, now always.
@@ -318,7 +351,7 @@ object MultipartParser { | |||
} else if (currState == len) { | |||
splitCompleteMatch(middleChunked, currState, i, acc, carry, c) | |||
} else { | |||
splitPartialMatch(middleChunked, currState, i, acc, carry, c) | |||
splitPartialMatch0(middleChunked, currState, i, acc, carry, c) |
jmcardon
Apr 3, 2018
Author
Member
Sux but I had to do this because MiMa :(.
I messed up not making these private in the first place.
Sux but I had to do this because MiMa :(.
I messed up not making these private in the first place.
We can release this as 0.18.6 tonight. I'll give @ChristopherDavenport a chance to peruse it. |
|
[error] Error: Total 51, Failed 0, Errors 1, Passed 48, Skipped 2, Pending 1
[error] Error during tests:
[error] org.http4s.client.blaze.ClientTimeoutSpec wat |
Closes #1755 .
Fixes a bug happening on uneven chunks + chunks that ended on a partial match with the boundary, but the boundary was contained in the middle of the chunk.