Skip to content

Fix flawed termination condition check in HttpPostRequestEncoder… (#1…#14870

Merged
normanmaurer merged 1 commit into4.2from
multi_42
Feb 28, 2025
Merged

Fix flawed termination condition check in HttpPostRequestEncoder… (#1…#14870
normanmaurer merged 1 commit into4.2from
multi_42

Conversation

@normanmaurer
Copy link
Copy Markdown
Member

…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 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.

…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>
@normanmaurer normanmaurer merged commit 35a03dd into 4.2 Feb 28, 2025
17 checks passed
@normanmaurer normanmaurer deleted the multi_42 branch February 28, 2025 06:08
@normanmaurer normanmaurer added this to the 4.2.0.RC4 milestone Feb 28, 2025
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.

2 participants