java: allow bounding decoder output to mitigate decompression bombs#1499
java: allow bounding decoder output to mitigate decompression bombs#1499hyperxpro wants to merge 1 commit into
Conversation
|
Hi. Thanks for your PR. I like the intent and motivation, let's polish the implementation details. It is not clearly stated in API, but Idiomatic Java propels the IO chains to achieve desired properties. So, given that chunk size is not unbound, we should rely on user wits to wrap data source into limiting filter. Thus, the only vulnerable part is one-shot decoding. (Truth to be said, one-shot decoding should never be used in production, only for tests / utils; but that is public API and we can't stop users from using it). Changes to Thanks again. |
Motivation:
One-shot Decoder.decompress reads a whole stream into memory with no size limit, so a small malicious input can expand to gigabytes and crash the JVM. Streaming decode is already chunk-bounded (BrotliDecoderTakeOutput caps a chunk), so one-shot is the only exposed path.
Modification:
Added Decoder.Parameters with setMaxOutputSize, plus decompress(data, params) and decompress(data, offset, length, params) overloads. decompress throws once the decoded size passes the limit. This mirrors output_buffer_limit on the Python side and the existing Encoder.Parameters. Pure Java, no native change; existing decompress methods are unchanged.
Result:
Callers can cap one-shot decode output when reading untrusted input.