-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Issue #11310 - multipart parser dropping some relevant CR bytes in parts #11409
Issue #11310 - multipart parser dropping some relevant CR bytes in parts #11409
Conversation
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.
@lachlan-roberts can you look at this?
jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/MultiPart.java
Outdated
Show resolved
Hide resolved
I've looked a little bit more at this and I think we need to never emit a content chunk that ends with a CR, as that may be the first byte of a CRLF preceding a boundary. We will still need the I think we can better utilize the existing |
Not sure what you mean here, but we do emit the content chunk excluding the last CR, which we remember in the boolean until we have another chunk to parse. Not sure I understand the rest of your comment, but I found and fixed another bug. |
…he boundary. Added and fixed related tests. Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
I think I have convinced myself this is correct.... but I also think it needs either some better comments, and/or perhaps some simplifications. |
jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/MultiPartFormDataTest.java
Outdated
Show resolved
Hide resolved
Sorry @gregw, I liked the code better before your changes, as it was clearer what cases did what. Also, most of your added comments are just repetitions of what the code does on the next line, so they are unnecessary, and they will rotten away if the code changes. Lastly, can you please be consistent and start all your comment with a capital letter and end with a period? (Sorry to be pedantic on this, but it's really confusing -- also the "conversation" style of the comments make you re-read from above otherwise the comment is out of context). |
@sbordet if it is just the fall throughs that you don't like, then let me put the if elses back, as I think there were some good simplifications even without that. If you don't like that, then I'll revert both commits and give a negative review on the bits that I found very confusing and let you have a go of either improving them or better comments. standby... |
b0cd639
to
781105f
Compare
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.
The logic needs cleanup and better comments
jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/MultiPart.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/MultiPart.java
Outdated
Show resolved
Hide resolved
jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/MultiPart.java
Show resolved
Hide resolved
@@ -1339,7 +1339,8 @@ private boolean parseContent(Content.Chunk chunk) | |||
} | |||
else | |||
{ | |||
// The boundary was partially matched. | |||
// The boundary was partially matched, but it |
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.
This section is confusing with nested if structure:
if (boudnaryMatch > 0)
{
if (boundaryMath == X)
{
// A
}
else
{
// B
}
}
else
{
// C
}
This should be:
if (boudnaryMatch > 0)
{
// A
}
else if (boundaryMath == X)
{
// B
}
else
{
// C
}
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.
It is not equivalent.
In your version, when boundaryMatch == X
it will execute the branch where boundaryMatch > 0
, which is wrong.
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.
Ooops I meant:
if (boudnaryMatch == X)
{
// A
}
else if (boundaryMath > 0)
{
// B
}
else
{
// C
}
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
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.
I still think the logic can be cleaned up more in this class.... but let's get the CR fix in.
Fixing the MultiPart.Parser handling of part content that would drop occasional CR bytes if the CR occurs at the border of a network buffer.
This was fixed in PR #11388 (as the bug was first isolated during testing in that PR) but this is more fundamental bug unrelated to the goals of that PR so I created a standalone PR for this bug (also so that it shows up in the changelog for 12.0.7 appropriately)
Fixes #11310