GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||
GeezerVison is showing github.com — Fix JZlibDecoder truncating highly compressible streams by renechoi · Pull Request #17392 · netty/netty Conversation
Contributor
MotivationJZlibDecoder sizes each output buffer from the remaining compressed input. For highly compressible raw deflate streams, JZlib can consume the last input byte while decoded bytes remain buffered. The next zero-sized output buffer makes inflate return Z_BUF_ERROR, and the decoder silently emits a short body.
ModificationApply the same floor while draining JZlib. Add parameterized coverage for the downstream-forwarding and fragmented-input paths, with each compressed fixture cross-checked by the JDK inflater. ResultRaw streams of 65,537 bytes in one write and 33,333 bytes in 7-byte chunks are fully decoded. codec-compression passes 508 tests, and
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsMotivation: JZlibDecoder sizes each output buffer from the remaining compressed input. JZlib may consume the last input byte while decoded bytes are still pending, which can make the next buffer zero-sized and silently truncate raw streams. Modifications: Keep a 512-byte minimum output buffer while draining JZlib. Add parameterized coverage for both downstream forwarding and fragmented input, with an independent JDK inflater cross-check. Result: Highly compressible raw streams are fully decoded in both paths.
|
There was an error while loading. Please reload this page.
🚨 TestLens detected 1 failed test 🚨Here is what you can do:
Test SummaryBuild PR / linux-x86_64-java11-pooled build > Netty/Common
🏷️ Commit: 264fab9 Test FailuresSingleThreadEventExecutorTest > testNotSuspendedUntilScheduledTaskIsCancelled() (Netty/Common in Build PR / linux-x86_64-java11-pooled build)Rerun ControlsSelect tests to mute in this pull request:
Reuse successful test results:
Click the checkbox to trigger a rerun:
Learn more about TestLens at testlens.app/docs. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Motivation: Since #17370 (and #17392 for `JZlibDecoder`), the zlib decoders ask `ZlibDecoder.prepareDecompressBuffer(...)` for at least 512 bytes (`MIN_OUTPUT_BUFFER_SIZE`) whenever an `inflate` call did not finish the stream. `prepareDecompressBuffer` throws as soon as `ensureWritable(preferredSize, true)` returns 1, that is, when the buffer is already at `maxAllocation` and has fewer writable bytes than requested. It does not check whether the buffer still has room. So with a `maxAllocation` of 512 or less, the decoder throws `DecompressionException: Decompression buffer has reached maximum size` for every stream that arrives in more than one read, even when the buffer is empty. For example, a ZLIB stream of 36 bytes of output with `maxAllocation = 375`, split into two reads, is rejected. With a larger `maxAllocation` the same happens once the buffer holds more than `maxAllocation - 512` bytes and the stream continues, although the remaining space would be used by the next `inflate` call. Measured with 2,000 random streams per row and wrapper (ZLIB, GZIP, NONE), split into two reads, whose whole output fits into `maxAllocation`: | `maxAllocation` | `JdkZlibDecoder` 4.2.18 | before #17370 | with this change | |---|---|---|---| | 1-512 | 73-100% fail | 0 | 0 (1) | | 513-1100 | about 8% fail | 0 | 0 | | 4096-70000 | 2 of 6,000 fail | 0 | 0 | (1) except when one read produces exactly `maxAllocation` bytes and the stream continues; see below. `JZlibDecoder` also requests `max(2 * remaining input, 512)` bytes before its first `inflate`. When `2 * input > maxAllocation`, an input whose output fits is rejected before any byte is decompressed: a single read that holds a ZLIB stream of 600 random bytes fails with `maxAllocation = 1024`. That part predates #17392. #17364 was merged into 4.1 as well, so 4.1.138.Final has the same behaviour for `JdkZlibDecoder`. The javadoc of `prepareDecompressBuffer` already says that it calls `decompressionBufferExhausted(...)` "if the buffer is full and cannot be expanded further". Modification: - In `ZlibDecoder.prepareDecompressBuffer(...)`, only give up when the buffer could not be expanded and has no writable byte left. Until then the decoder keeps inflating into the space that is left, and a stream whose output exceeds `maxAllocation` still fails as before. - New tests in `ZlibTest`, so they run for both `JdkZlibDecoder` and `JZlibDecoder`: - `@ParameterizedTest` over ZLIB, GZIP and NONE with `maxAllocation` 2, 64 and 512: an output smaller than `maxAllocation`, decoded in one read, in two reads and byte by byte; - `@ParameterizedTest` over 600, 1000 and 1024 incompressible bytes with `maxAllocation = 1024` in one read. - a guard, `@ParameterizedTest` over ZLIB, GZIP and NONE with `maxAllocation` 64, and ZLIB with 512: 64 KiB of zeros (about 100 bytes compressed) in one read is still rejected with "Decompression buffer has reached maximum size", so the limit keeps protecting against small inputs with a large output. Result: `maxAllocation` limits the output of a read again, without rejecting streams whose output fits.
… is full (#17698) Auto-port of #17692 to 4.1 Cherry-picked commit: e6fc471 --- Motivation: Since #17370 (and #17392 for `JZlibDecoder`), the zlib decoders ask `ZlibDecoder.prepareDecompressBuffer(...)` for at least 512 bytes (`MIN_OUTPUT_BUFFER_SIZE`) whenever an `inflate` call did not finish the stream. `prepareDecompressBuffer` throws as soon as `ensureWritable(preferredSize, true)` returns 1, that is, when the buffer is already at `maxAllocation` and has fewer writable bytes than requested. It does not check whether the buffer still has room. So with a `maxAllocation` of 512 or less, the decoder throws `DecompressionException: Decompression buffer has reached maximum size` for every stream that arrives in more than one read, even when the buffer is empty. For example, a ZLIB stream of 36 bytes of output with `maxAllocation = 375`, split into two reads, is rejected. With a larger `maxAllocation` the same happens once the buffer holds more than `maxAllocation - 512` bytes and the stream continues, although the remaining space would be used by the next `inflate` call. Measured with 2,000 random streams per row and wrapper (ZLIB, GZIP, NONE), split into two reads, whose whole output fits into `maxAllocation`: | `maxAllocation` | `JdkZlibDecoder` 4.2.18 | before #17370 | with this change | |---|---|---|---| | 1-512 | 73-100% fail | 0 | 0 (1) | | 513-1100 | about 8% fail | 0 | 0 | | 4096-70000 | 2 of 6,000 fail | 0 | 0 | (1) except when one read produces exactly `maxAllocation` bytes and the stream continues; see below. `JZlibDecoder` also requests `max(2 * remaining input, 512)` bytes before its first `inflate`. When `2 * input > maxAllocation`, an input whose output fits is rejected before any byte is decompressed: a single read that holds a ZLIB stream of 600 random bytes fails with `maxAllocation = 1024`. That part predates #17392. #17364 was merged into 4.1 as well, so 4.1.138.Final has the same behaviour for `JdkZlibDecoder`. The javadoc of `prepareDecompressBuffer` already says that it calls `decompressionBufferExhausted(...)` "if the buffer is full and cannot be expanded further". Modification: - In `ZlibDecoder.prepareDecompressBuffer(...)`, only give up when the buffer could not be expanded and has no writable byte left. Until then the decoder keeps inflating into the space that is left, and a stream whose output exceeds `maxAllocation` still fails as before. - New tests in `ZlibTest`, so they run for both `JdkZlibDecoder` and `JZlibDecoder`: - `@ParameterizedTest` over ZLIB, GZIP and NONE with `maxAllocation` 2, 64 and 512: an output smaller than `maxAllocation`, decoded in one read, in two reads and byte by byte; - `@ParameterizedTest` over 600, 1000 and 1024 incompressible bytes with `maxAllocation = 1024` in one read. - a guard, `@ParameterizedTest` over ZLIB, GZIP and NONE with `maxAllocation` 64, and ZLIB with 512: 64 KiB of zeros (about 100 bytes compressed) in one read is still rejected with "Decompression buffer has reached maximum size", so the limit keeps protecting against small inputs with a large output. Result: `maxAllocation` limits the output of a read again, without rejecting streams whose output fits. --------- Co-authored-by: allthingssecurity <[email protected]> Co-authored-by: Norman Maurer <[email protected]>
…17698) (#17704) Motivation: Since #17370 (and #17392 for `JZlibDecoder`), the zlib decoders ask `ZlibDecoder.prepareDecompressBuffer(...)` for at least 512 bytes (`MIN_OUTPUT_BUFFER_SIZE`) whenever an `inflate` call did not finish the stream. `prepareDecompressBuffer` throws as soon as `ensureWritable(preferredSize, true)` returns 1, that is, when the buffer is already at `maxAllocation` and has fewer writable bytes than requested. It does not check whether the buffer still has room. So with a `maxAllocation` of 512 or less, the decoder throws `DecompressionException: Decompression buffer has reached maximum size` for every stream that arrives in more than one read, even when the buffer is empty. For example, a ZLIB stream of 36 bytes of output with `maxAllocation = 375`, split into two reads, is rejected. With a larger `maxAllocation` the same happens once the buffer holds more than `maxAllocation - 512` bytes and the stream continues, although the remaining space would be used by the next `inflate` call. Measured with 2,000 random streams per row and wrapper (ZLIB, GZIP, NONE), split into two reads, whose whole output fits into `maxAllocation`: | `maxAllocation` | `JdkZlibDecoder` 4.2.18 | before #17370 | with this change | |---|---|---|---| | 1-512 | 73-100% fail | 0 | 0 (1) | | 513-1100 | about 8% fail | 0 | 0 | | 4096-70000 | 2 of 6,000 fail | 0 | 0 | (1) except when one read produces exactly `maxAllocation` bytes and the stream continues; see below. `JZlibDecoder` also requests `max(2 * remaining input, 512)` bytes before its first `inflate`. When `2 * input > maxAllocation`, an input whose output fits is rejected before any byte is decompressed: a single read that holds a ZLIB stream of 600 random bytes fails with `maxAllocation = 1024`. That part predates #17392. behaviour for `JdkZlibDecoder`. The javadoc of `prepareDecompressBuffer` already says that it calls `decompressionBufferExhausted(...)` "if the buffer is full and cannot be expanded further". Modification: - In `ZlibDecoder.prepareDecompressBuffer(...)`, only give up when the buffer could not be expanded and has no writable byte left. Until then the decoder keeps inflating into the space that is left, and a stream whose output exceeds `maxAllocation` still fails as before. - New tests in `ZlibTest`, so they run for both `JdkZlibDecoder` and `JZlibDecoder`: - `@ParameterizedTest` over ZLIB, GZIP and NONE with `maxAllocation` 2, 64 and 512: an output smaller than `maxAllocation`, decoded in one read, in two reads and byte by byte; - `@ParameterizedTest` over 600, 1000 and 1024 incompressible bytes with `maxAllocation = 1024` in one read. - a guard, `@ParameterizedTest` over ZLIB, GZIP and NONE with `maxAllocation` 64, and ZLIB with 512: 64 KiB of zeros (about 100 bytes compressed) in one read is still rejected with "Decompression buffer has reached maximum size", so the limit keeps protecting against small inputs with a large output. Result: `maxAllocation` limits the output of a read again, without rejecting streams whose output fits. --------- Co-authored-by: allthingssecurity <[email protected]> Co-authored-by: Norman Maurer <[email protected]> Co-authored-by: Netty Project Bot <[email protected]> Co-authored-by: allthingssecurity <[email protected]>
… is full (netty#17698) Auto-port of netty#17692 to 4.1 Cherry-picked commit: e6fc471 --- Motivation: Since netty#17370 (and netty#17392 for `JZlibDecoder`), the zlib decoders ask `ZlibDecoder.prepareDecompressBuffer(...)` for at least 512 bytes (`MIN_OUTPUT_BUFFER_SIZE`) whenever an `inflate` call did not finish the stream. `prepareDecompressBuffer` throws as soon as `ensureWritable(preferredSize, true)` returns 1, that is, when the buffer is already at `maxAllocation` and has fewer writable bytes than requested. It does not check whether the buffer still has room. So with a `maxAllocation` of 512 or less, the decoder throws `DecompressionException: Decompression buffer has reached maximum size` for every stream that arrives in more than one read, even when the buffer is empty. For example, a ZLIB stream of 36 bytes of output with `maxAllocation = 375`, split into two reads, is rejected. With a larger `maxAllocation` the same happens once the buffer holds more than `maxAllocation - 512` bytes and the stream continues, although the remaining space would be used by the next `inflate` call. Measured with 2,000 random streams per row and wrapper (ZLIB, GZIP, NONE), split into two reads, whose whole output fits into `maxAllocation`: | `maxAllocation` | `JdkZlibDecoder` 4.2.18 | before netty#17370 | with this change | |---|---|---|---| | 1-512 | 73-100% fail | 0 | 0 (1) | | 513-1100 | about 8% fail | 0 | 0 | | 4096-70000 | 2 of 6,000 fail | 0 | 0 | (1) except when one read produces exactly `maxAllocation` bytes and the stream continues; see below. `JZlibDecoder` also requests `max(2 * remaining input, 512)` bytes before its first `inflate`. When `2 * input > maxAllocation`, an input whose output fits is rejected before any byte is decompressed: a single read that holds a ZLIB stream of 600 random bytes fails with `maxAllocation = 1024`. That part predates netty#17392. netty#17364 was merged into 4.1 as well, so 4.1.138.Final has the same behaviour for `JdkZlibDecoder`. The javadoc of `prepareDecompressBuffer` already says that it calls `decompressionBufferExhausted(...)` "if the buffer is full and cannot be expanded further". Modification: - In `ZlibDecoder.prepareDecompressBuffer(...)`, only give up when the buffer could not be expanded and has no writable byte left. Until then the decoder keeps inflating into the space that is left, and a stream whose output exceeds `maxAllocation` still fails as before. - New tests in `ZlibTest`, so they run for both `JdkZlibDecoder` and `JZlibDecoder`: - `@ParameterizedTest` over ZLIB, GZIP and NONE with `maxAllocation` 2, 64 and 512: an output smaller than `maxAllocation`, decoded in one read, in two reads and byte by byte; - `@ParameterizedTest` over 600, 1000 and 1024 incompressible bytes with `maxAllocation = 1024` in one read. - a guard, `@ParameterizedTest` over ZLIB, GZIP and NONE with `maxAllocation` 64, and ZLIB with 512: 64 KiB of zeros (about 100 bytes compressed) in one read is still rejected with "Decompression buffer has reached maximum size", so the limit keeps protecting against small inputs with a large output. Result: `maxAllocation` limits the output of a read again, without rejecting streams whose output fits. --------- Co-authored-by: allthingssecurity <[email protected]> Co-authored-by: Norman Maurer <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.