diff --git a/codec-socks/src/main/java/io/netty/handler/codec/socksx/v5/Socks5CmdRequestDecoder.java b/codec-socks/src/main/java/io/netty/handler/codec/socksx/v5/Socks5CmdRequestDecoder.java index 44609fd88e..33297d760c 100755 --- a/codec-socks/src/main/java/io/netty/handler/codec/socksx/v5/Socks5CmdRequestDecoder.java +++ b/codec-socks/src/main/java/io/netty/handler/codec/socksx/v5/Socks5CmdRequestDecoder.java @@ -75,7 +75,18 @@ public class Socks5CmdRequestDecoder extends ReplayingDecoder { break; } case IPv6: { - host = Socks5CommonUtils.ipv6toStr(byteBuf.readBytes(16).array()); + if (actualReadableBytes() < 16) { + // Let it replay. + byteBuf.readBytes(16); + + // Should never reach here. + throw new Error(); + } + + byte[] byteArray = new byte[16]; + byteBuf.readBytes(byteArray); + + host = Socks5CommonUtils.ipv6toStr(byteArray); port = byteBuf.readUnsignedShort(); msg = new Socks5CmdRequest(cmdType, addressType, host, port); break;