Netty version: 4.2.115
Expected behavior
HttpContentDecompressor(int maxAllocation) documents maxAllocation as "maximum size of the decompression buffer". For gzip, deflate and zstd encodings the value is routed to each decoder's output-cap parameter (ZlibDecoder.maxAllocation, ZstdDecoder.maximumAllocationSize), which correctly bounds the size of each emitted decompressed chunk.
Actual behavior
For br (brotli) encoding, HttpContentDecompressor#newContentDecoder calls:
new BrotliDecoder(maxAllocation)
The single-argument BrotliDecoder(int) constructor treats its parameter as inputBufferSize, not as the decompression output cap:
public BrotliDecoder(int inputBufferSize) {
this(inputBufferSize == 0 ? DEFAULT_INPUT_BUFFER_SIZE : inputBufferSize,
DEFAULT_MAX_FORWARD_BYTES); // outputBufferSize stays at the 64KB default
}
Consequences:
A user setting a large maxAllocation (16 * 1024 * 1024) intending to allow up to 16 MiB of decompressed output actually enlarges brotli's input buffer to 16 MiB while the output cap stays pinned at 64 KiB.
A user setting a small maxAllocation (64 * 1024) does not tighten the output cap for brotli; it silently ends up equal to the default.
The "0 = unlimited" convention (used by the other decoders in the same class) cannot be expressed for brotli — 0 falls back to the 8 KiB input-buffer default.
I have a regression test that shows a 128 KiB payload with HttpContentDecompressor(64) currently emits only 2 large chunks (outputBufferSize = 64 KiB default) instead of many small chunks bounded by 64 bytes.
Steps to reproduce
// Compress 128 KiB with brotli (any compressible content), then:
EmbeddedChannel ch = new EmbeddedChannel(new HttpContentDecompressor(64));
// send response + content...
// Drain HttpContent chunks: chunk count is ~2 instead of ~2000
Full reproducer available.
Proposed fix
Two reasonable options, I can create the PR for whichever the maintainers prefer:
A. Add a factory on BrotliDecoder that mirrors the maxAllocation semantics of the other decoders and route HttpContentDecompressor through it:
public static BrotliDecoder newDecoderWithMaxAllocation(int maxAllocation) {
return maxAllocation > 0
? new BrotliDecoder(DEFAULT_INPUT_BUFFER_SIZE, maxAllocation)
: new BrotliDecoder();
}
B. Localize the fix in HttpContentDecompressor using a duplicated constant to pick the two-arg brotli constructor (keeps BrotliDecoder's API unchanged).
Option A is cleaner (single source of truth for the input-buffer default), option B is smaller (no codec-compression changes).
Additional notes
Fix is behavior-change-visible for users who currently rely on HttpContentDecompressor(int) to shape brotli's input buffer, though that reliance would already be inconsistent with the parameter's documented meaning.
Related but out of scope: HttpContentDecompressor(int) comment could clarify the "0 = unlimited" semantics.