From 9a3be347af35107201f7d4a72416e76cf6b39a82 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Sat, 22 Sep 2018 13:34:12 -0700 Subject: [PATCH] Ensure we always encode all data in JdkZlibEncoder. (#8305) Motivation: In theory our estimation of the needed buffer could be off and so we need to ensure we grow it if there is no space left. Modifications: Ensure we grow the buffer if there is no space left in there but we still have data to deflate. Result: Correctly deflate data in all cases. --- .../handler/codec/compression/JdkZlibEncoder.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/codec/src/main/java/io/netty/handler/codec/compression/JdkZlibEncoder.java b/codec/src/main/java/io/netty/handler/codec/compression/JdkZlibEncoder.java index f039fa66e8..276d7f86b0 100644 --- a/codec/src/main/java/io/netty/handler/codec/compression/JdkZlibEncoder.java +++ b/codec/src/main/java/io/netty/handler/codec/compression/JdkZlibEncoder.java @@ -225,8 +225,18 @@ public class JdkZlibEncoder extends ZlibEncoder { } deflater.setInput(inAry, offset, len); - while (!deflater.needsInput()) { + for (;;) { deflate(out); + if (deflater.needsInput()) { + // Consumed everything + break; + } else { + if (!out.isWritable()) { + // We did not consume everything but the buffer is not writable anymore. Increase the capacity to + // make more room. + out.ensureWritable(out.writerIndex()); + } + } } }