-
Notifications
You must be signed in to change notification settings - Fork 787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix parsing of uneven stream bodies #1764
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -222,7 +222,6 @@ object MultipartParser { | |
* | ||
*/ | ||
private def splitCompleteMatch[F[_]: Sync]( | ||
state: Int, | ||
middleChunked: Boolean, | ||
sti: Int, | ||
i: Int, | ||
|
@@ -236,12 +235,6 @@ object MultipartParser { | |
//Emit the partial match as well | ||
acc ++ carry ++ Stream.chunk(c.take(i - sti)), | ||
Stream.chunk(c.drop(i))) //Emit after the match | ||
} else if (state == 0) { | ||
( | ||
sti, | ||
//Ignore the partial match (carry) | ||
acc ++ Stream.chunk(c.take(i - sti)), | ||
Stream.chunk(c.drop(i))) | ||
} else { | ||
( | ||
sti, | ||
|
@@ -265,7 +258,6 @@ object MultipartParser { | |
* | ||
*/ | ||
def splitPartialMatch[F[_]: Sync]( | ||
state: Int, | ||
middleChunked: Boolean, | ||
currState: Int, | ||
i: Int, | ||
|
@@ -274,7 +266,7 @@ object MultipartParser { | |
c: Chunk[Byte] | ||
): (Int, Stream[F, Byte], Stream[F, Byte]) = { | ||
val ixx = i - currState | ||
if (middleChunked || state == 0) { | ||
if (middleChunked) { | ||
val (lchunk, rchunk) = c.splitAt(ixx) | ||
(currState, acc ++ carry ++ Stream.chunk(lchunk), Stream.chunk(rchunk)) | ||
} else { | ||
|
@@ -305,25 +297,28 @@ object MultipartParser { | |
var i = 0 | ||
var currState = state | ||
val len = values.length | ||
var middleChunked = false | ||
while (currState < len && i < c.size) { | ||
if (c(i) == values(currState)) { | ||
currState += 1 | ||
} else if (c(i) == values(0)) { | ||
middleChunked = true | ||
currState = 1 | ||
} else { | ||
currState = 0 | ||
} | ||
i += 1 | ||
} | ||
//It will only be zero if | ||
//the chunk matches from the very beginning, | ||
//since currstate can never be greater than | ||
//(i + state). | ||
val middleChunked = i + state - currState > 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some background on this condition to help review:
|
||
|
||
if (currState == 0) { | ||
(0, acc ++ carry ++ Stream.chunk(c), Stream.empty) | ||
} else if (currState == len) { | ||
splitCompleteMatch(state, middleChunked, currState, i, acc, carry, c) | ||
splitCompleteMatch(middleChunked, currState, i, acc, carry, c) | ||
} else { | ||
splitPartialMatch(state, middleChunked, currState, i, acc, carry, c) | ||
splitPartialMatch(middleChunked, currState, i, acc, carry, c) | ||
} | ||
} | ||
|
||
|
@@ -540,13 +535,6 @@ object MultipartParser { | |
//Emit after the match | ||
Stream.chunk(c.drop(i)), | ||
state + i - sti) | ||
} else if (state == 0) { | ||
( | ||
sti, | ||
//Ignore the partial match (carry) | ||
acc ++ Stream.chunk(c.take(i - sti)), | ||
Stream.chunk(c.drop(i)), | ||
i - sti) | ||
} else { | ||
( | ||
sti, | ||
|
@@ -580,7 +568,7 @@ object MultipartParser { | |
c: Chunk[Byte] | ||
): (Int, Stream[F, Byte], Stream[F, Byte], Int) = { | ||
val ixx = i - currState | ||
if (middleChunked || state == 0) { | ||
if (middleChunked) { | ||
val (lchunk, rchunk) = c.splitAt(ixx) | ||
( | ||
currState, | ||
|
@@ -602,19 +590,23 @@ object MultipartParser { | |
var i = 0 | ||
var currState = state | ||
val len = values.length | ||
var middleChunked = false | ||
while (currState < len && i < c.size) { | ||
if (c(i) == values(currState)) { | ||
currState += 1 | ||
} else if (c(i) == values(0)) { | ||
middleChunked = true | ||
currState = 1 | ||
} else { | ||
currState = 0 | ||
} | ||
i += 1 | ||
} | ||
|
||
//It will only be zero if | ||
//the chunk matches from the very beginning, | ||
//since currstate can never be greater than | ||
//(i + state). | ||
val middleChunked = i + state - currState > 0 | ||
|
||
if (currState == 0) { | ||
(0, acc ++ carry ++ Stream.chunk(c), Stream.empty, i) | ||
} else if (currState == len) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
state == 0 condition was removed because it is not longer necessary: this case will be picked up as a
middleChunked
case, now always.