Skip to content

Return null in HttpPostRequestEncoder#9352

Merged
normanmaurer merged 3 commits intonetty:4.1from
emlittleworth:elittleworth/npe
Jul 16, 2019
Merged

Return null in HttpPostRequestEncoder#9352
normanmaurer merged 3 commits intonetty:4.1from
emlittleworth:elittleworth/npe

Conversation

@emlittleworth
Copy link
Copy Markdown
Contributor

Motivation:

If the encoded value of a form element happens to exactly hit the chunk limit (8096 bytes), the post request encoder will throw a NullPointerException.

Modification:

Catch the null case and return.

Result:

Fixes #9351.

Motivation:

If the encoded value of a form element happens to exactly hit
the chunk limit (8096 bytes), the post request encoder will
throw a NullPointerException.

Modifications:

Catch the null case and return.

Result:

No NPE.

HttpRequest finalRequest = encoder.finalizeRequest();

ch.writeOutbound(finalRequest);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add assert for return value

HttpRequest finalRequest = encoder.finalizeRequest();

ch.writeOutbound(finalRequest);
ch.writeOutbound(encoder);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add assert for return value


ch.writeOutbound(finalRequest);
ch.writeOutbound(encoder);
ch.flushOutbound();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call ch.finish() and assert return value .


@Test
public void testEncodeChunkedContent() throws Exception {
EmbeddedChannel ch = new EmbeddedChannel(new ChunkedWriteHandler());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the ChunkedWriteHandler needed ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the closest thing I could find to the logic in Finagle. I just changed it though.

@netty-bot
Copy link
Copy Markdown

Can one of the admins verify this patch?

assertNotNull(encoder.finalizeRequest());

while (!encoder.isEndOfInput()) {
encoder.readChunk((ByteBufAllocator) null);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to also release the HttpContent returned by this method as otherwise the test will leak memory:

encoder.readChunk(...).release()

@normanmaurer
Copy link
Copy Markdown
Member

@netty-bot test this please

@normanmaurer normanmaurer added this to the 4.1.38.Final milestone Jul 16, 2019
@normanmaurer normanmaurer merged commit d07d7e2 into netty:4.1 Jul 16, 2019
@normanmaurer
Copy link
Copy Markdown
Member

@emlittleworth thanks a lot!

normanmaurer pushed a commit that referenced this pull request Jul 16, 2019
Motivation:

If the encoded value of a form element happens to exactly hit
the chunk limit (8096 bytes), the post request encoder will
throw a NullPointerException.

Modifications:

Catch the null case and return.

Result:

No NPE.
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.

NullPointerException in HttpPostRequestEncoder encodeNextChunkUrlEncoded

3 participants