From 8d3ef3a80efa6fd339437b36c3f0557ef586ebec Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Mon, 11 Apr 2016 10:15:19 +0200 Subject: [PATCH] [#4635] Stop decoding if decoder was removed in ReplayingDecoder We need to check if this handler was removed before continuing with decoding. If it was removed, it is not safe to continue to operate on the buffer. This was already fixed for ByteToMessageDecoder in 4cdbe3928424b5b38695967c0cc1062dccf1a83c but missed for ReplayingDecoder. Modifications: Check if decoder was removed after fire messages through the pipeline. Result: No illegal buffer access when decoder was removed. --- .../java/io/netty/handler/codec/ReplayingDecoder.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/codec/src/main/java/io/netty/handler/codec/ReplayingDecoder.java b/codec/src/main/java/io/netty/handler/codec/ReplayingDecoder.java index 1f03e9160e..67c33c7880 100644 --- a/codec/src/main/java/io/netty/handler/codec/ReplayingDecoder.java +++ b/codec/src/main/java/io/netty/handler/codec/ReplayingDecoder.java @@ -367,6 +367,15 @@ public abstract class ReplayingDecoder extends ByteToMessageDecoder { if (outSize > 0) { fireChannelRead(ctx, out, outSize); out.clear(); + + // Check if this handler was removed before continuing with decoding. + // If it was removed, it is not safe to continue to operate on the buffer. + // + // See: + // - https://github.com/netty/netty/issues/4635 + if (ctx.isRemoved()) { + break; + } outSize = 0; }