Skip to content

Fix flawed termination condition check in HttpPostRequestEncoder…#14799

Merged
normanmaurer merged 2 commits intonetty:4.1from
LinShunKang:4.1
Feb 27, 2025
Merged

Fix flawed termination condition check in HttpPostRequestEncoder…#14799
normanmaurer merged 2 commits intonetty:4.1from
LinShunKang:4.1

Conversation

@LinShunKang
Copy link
Copy Markdown
Contributor

@LinShunKang LinShunKang commented Feb 11, 2025

…#encodeNextChunkUrlEncoded(int) for current InterfaceHttpData

Motivation:

I am using HttpPostRequestEncoder to encode a few request parameters, but I read infinite chunks when the following conditions are met:

  1. The number of POST request parameters is greater than or equal to 2.
  2. The length of the first request parameter value > DefaultHttpDataFactory#minSize.
  3. The length of the first request parameter key + the length of the request parameter value + 2 = N * HttpPostBodyUtil#chunkSize

This issue can be reproduced by modifying the length variable in the HttpPostRequestEncoderTest#testEncodeChunkedContent() method to HttpPostBodyUtil.chunkSize * 3 - 4 - 2. Normally, this test method should complete quickly, but when the length variable is set to HttpPostBodyUtil.chunkSize * 3 - 4 - 2, it will never finish.

Modification:

  1. Enhance the logic of determining whether the current InterfaceHttpData has been fully read.

Result:

Fix flawed termination condition check.

…#encodeNextChunkUrlEncoded(int) for current InterfaceHttpData
@LinShunKang LinShunKang marked this pull request as draft February 12, 2025 12:44
…deNextChunkUrlEncoded(int) for current InterfaceHttpData
@LinShunKang LinShunKang marked this pull request as ready for review February 12, 2025 16:47
@LinShunKang LinShunKang changed the title Fix: fix flawed termination condition check in HttpPostRequestEncoder… Fix flawed termination condition check in HttpPostRequestEncoder… Feb 13, 2025
@LinShunKang
Copy link
Copy Markdown
Contributor Author

@normanmaurer PTAL

@normanmaurer
Copy link
Copy Markdown
Member

@yawkat can you have a look maybe ?

@yawkat
Copy link
Copy Markdown
Contributor

yawkat commented Feb 26, 2025

LGTM

@normanmaurer
Copy link
Copy Markdown
Member

@LinShunKang did you sign our icla ? https://netty.io/s/icla ?

@LinShunKang
Copy link
Copy Markdown
Contributor Author

@LinShunKang did you sign our icla ? https://netty.io/s/icla ?

Yes, I have signed it.

@normanmaurer normanmaurer merged commit 24479a0 into netty:4.1 Feb 27, 2025
14 of 15 checks passed
normanmaurer pushed a commit that referenced this pull request Feb 27, 2025
…4799)

…#encodeNextChunkUrlEncoded(int) for current InterfaceHttpData

Motivation:

I am using `HttpPostRequestEncoder` to encode a few request parameters,
but I read **infinite** chunks when the following conditions are met:

1. The number of POST request parameters is greater than or equal to 2.
2. The length of the first request parameter value >
`DefaultHttpDataFactory#minSize`.
3. The length of the first request parameter key + the length of the
request parameter value + 2 = N * `HttpPostBodyUtil#chunkSize`

This issue can be reproduced by modifying the
[length](https://github.com/netty/netty/blob/34011b5f02c52122eccd36ce7cc69502a514d0f1/codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoderTest.java#L454)
variable in the
[HttpPostRequestEncoderTest#testEncodeChunkedContent()](https://github.com/netty/netty/blob/34011b5f02c52122eccd36ce7cc69502a514d0f1/codec-http/src/test/java/io/netty/handler/codec/http/multipart/HttpPostRequestEncoderTest.java#L450)
method to `HttpPostBodyUtil.chunkSize * 3 - 4 - 2`. Normally, this test
method should complete quickly, but when the length variable is set to
`HttpPostBodyUtil.chunkSize * 3 - 4 - 2`, it will never finish.

Modification:

1. Enhance the logic of determining whether the current
`InterfaceHttpData` has been fully read.

Result:

Fix flawed termination condition check.

---------

Co-authored-by: LinShunKang <linshunkang@kanzhun.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants