You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[API Proposal]: Add support for Brotli Large Window decompression #133018
BrotliStream and BrotliDecoder currently have no way to decode streams with large window sizes. The underlying native Brotli decoder supports "Large Window Brotli", but only behind a boolean switch ( BROTLI_DECODER_PARAM_LARGE_WINDOW ) that must be set before any data is processed.
API Proposal
namespace System.IO.Compression
{
public sealed class BrotliDecompressionOptions
{
public BrotliDecompressionOptions();
public int MaxWindowLog2 { get; set; } // default: 24
}
public partial struct BrotliDecoder : IDisposable
{
public BrotliDecoder(BrotliDecompressionOptions decompressionOptions);
}
public sealed partial class BrotliStream : Stream
{
public BrotliStream(Stream stream, BrotliDecompressionOptions decompressionOptions, bool leaveOpen = false);
}
}
API Usage
var options = new BrotliDecompressionOptions { MaxWindowLog2 = 27 };
using var brotli = new BrotliStream(pdfObjectStream, options);
using var decoder = new BrotliDecoder(new BrotliDecompressionOptions { MaxWindowLog2 = 27 });
Alternative Designs
bool EnableLargeWindow instead of a numeric ceiling. This maps directly onto the native switch and is the simplest possible shape.
A direct int maxWindowLog2 constructor overload, mirroring Zstandard, instead of requiring the options object. (Zstandard also has ZstandardDecompressionOptions with int MaxWindowLog2 inside.)
public ZstandardDecoder(int maxWindowLog2);
public ZstandardDecoder(ZstandardDictionary dictionary, int maxWindowLog2);
An alternative API design could expose the maximum accepted window size instead of a Boolean:
We might prefer this one for parity with Zstandard, if the native API allows expressing such policy, or at least if it is possible to query the information before the library actually allocates the working memory for it.
Does this require also a corresponding parameter on the encoder side? Being able to produce such payloads would simplify testing.
Yes, I think MaxWindowLog would be the better API for parity with Zstandard.
The native Brotli decoder only exposes BROTLI_DECODER_PARAM_LARGE_WINDOW as a Boolean; it does not provide a direct “maximum accepted window” parameter. However, the required window size is encoded in the stream header, so the .NET layer should be able to validate it against MaxWindowLog before committing to the corresponding large ring-buffer allocation. The native decoder already separates stream/window parsing from its ring-buffer allocation strategy.
I also think a corresponding encoder-side option is useful. The reference Brotli encoder supports Large Window streams up to lgwin=30 through --large_window, while the current normal Brotli range stops at 24.
That would allow straightforward round-trip and boundary tests, for example:
encode with window 24 → accepted by the default decoder
encode with window 25 → rejected with MaxWindowLog = 24, accepted with MaxWindowLog >= 25
encode with window 30 → accepted only when explicitly allowed
So I would favor something like BrotliDecompressionOptions.MaxWindowLog, together with an encoder option capable of producing Large Window payloads.
Activity
dotnet-policy-service commentedon Sep 1, 2026
Tagging subscribers to this area: @karelz, @dotnet/area-system-io-compression
See info in area-owners.md if you want to be subscribed.
rzikm commentedon Sep 1, 2026
We might prefer this one for parity with Zstandard, if the native API allows expressing such policy, or at least if it is possible to query the information before the library actually allocates the working memory for it.
Does this require also a corresponding parameter on the encoder side? Being able to produce such payloads would simplify testing.
KHDHaDi commentedon Sep 1, 2026
Yes, I think MaxWindowLog would be the better API for parity with Zstandard.
The native Brotli decoder only exposes BROTLI_DECODER_PARAM_LARGE_WINDOW as a Boolean; it does not provide a direct “maximum accepted window” parameter. However, the required window size is encoded in the stream header, so the .NET layer should be able to validate it against MaxWindowLog before committing to the corresponding large ring-buffer allocation. The native decoder already separates stream/window parsing from its ring-buffer allocation strategy.
I also think a corresponding encoder-side option is useful. The reference Brotli encoder supports Large Window streams up to lgwin=30 through --large_window, while the current normal Brotli range stops at 24.
That would allow straightforward round-trip and boundary tests, for example:
encode with window 24 → accepted by the default decoder
encode with window 25 → rejected with MaxWindowLog = 24, accepted with MaxWindowLog >= 25
encode with window 30 → accepted only when explicitly allowed
So I would favor something like BrotliDecompressionOptions.MaxWindowLog, together with an encoder option capable of producing Large Window payloads.
bartonjs commentedon Oct 13, 2026
Video
Looks good as proposed.