Skip to content

NullPointerException in HttpPostRequestEncoder #5478

@bfiorini

Description

@bfiorini

Hello,

There is a bug in the nextChunk() algorithm of the HttpPostRequestEncoder. When chunking a big request or multipart data, if the size of the resulting query is a multiple of the chunk size, isLastChunkSent is not set to true at the end, resulting in a NullPointerException.

This bug is present in version 3.10 as well as 4.x

Here is a unitest that shows this problem:

    @Test
    public void testNpe() throws Exception {
        DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1,
                HttpMethod.POST, "http://localhost");
        HttpPostRequestEncoder encoder = new HttpPostRequestEncoder(request, true);
        int length = 7943;
        char[] array = new char[length];
        Arrays.fill(array, 'a');
        String longText = new String(array);
        encoder.addBodyAttribute("foo", longText);
        encoder.finalizeRequest();

        while (! encoder.isEndOfInput()) {
            encoder.readChunk((ByteBufAllocator) null);
        }
    }

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions