GeezerVison is showing github.com — HTTP2: Don't leak buffer when using compression and the stream is clo… · lltopk/netty@e9cec3f
File tree
Expand file treeCollapse file tree
Open diff view settings
codec-http2/src/main/java/io/netty/handler/codec/http2
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: codec-http2/src/main/java/io/netty/handler/codec/http2/DelegatingDecompressorFrameListener.java +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
29 | 29 | import io.netty.handler.codec.compression.ZlibWrapper; |
30 | 30 | import io.netty.handler.codec.compression.SnappyFrameDecoder; |
31 | 31 |
|
| 32 | +import java.nio.channels.ClosedChannelException; |
| 33 | + |
32 | 34 | import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_ENCODING; |
33 | 35 | import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH; |
34 | 36 | import static io.netty.handler.codec.http.HttpHeaderValues.BR; |
@@ -429,6 +431,15 @@ int decompress(ChannelHandlerContext ctx, Http2Stream stream, ByteBuf data, int |
429 | 431 | this.dataDecompressed = false; |
430 | 432 | this.targetCtx = ctx; |
431 | 433 |
|
| 434 | + if (!decompressor.isOpen()) { |
| 435 | + // Directly throw an exception in this case which we will handle in the catch block below. |
| 436 | + // This is required as otherwise it will impossible for us to know if the used EmbeddedChannel |
| 437 | + // did throw because it was closed already or because of other reasons. We need this knowledge |
| 438 | + // to know if we need to call data.release() ourselves after it was retained or not. This is needed |
| 439 | + // as EmbeddedChannel will not release the buffer if it throws because it was not open. |
| 440 | + // This mimics what EmbeddedChannel will throw. |
| 441 | + throw new ClosedChannelException(); |
| 442 | + } |
432 | 443 | // call retain here as it will call release after its written to the channel |
433 | 444 | decompressor.writeInbound(data.retain()); |
434 | 445 | if (endOfStream) { |
|