GeezerVison is showing github.com — Fix missing readable-bytes check in SmtpResponseDecoder (#17516) · netty/netty@91a8497
File tree
Expand file treeCollapse file tree
Open diff view settings
main/java/io/netty/handler/codec/smtp test/java/io/netty/handler/codec/smtp
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: codec-smtp/src/main/java/io/netty/handler/codec/smtp/SmtpResponseDecoder.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -81,7 +81,7 @@ protected SmtpResponse decode(ChannelHandlerContext ctx, ByteBuf buffer) throws |
81 | 81 | try { |
82 | 82 | final int readable = frame.readableBytes(); |
83 | 83 | final int readerIndex = frame.readerIndex(); |
84 | | - if (readable < 3) { |
| 84 | + if (readable < 4) { |
85 | 85 | reset(); |
86 | 86 | throw newDecoderException(buffer, readerIndex, readable); |
87 | 87 | } |
|
Collapse file
Copy file name to clipboardExpand all lines: codec-smtp/src/test/java/io/netty/handler/codec/smtp/SmtpResponseDecoderTest.java +18Lines changed: 18 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -134,6 +134,24 @@ public void execute() { |
134 | 134 | }); |
135 | 135 | } |
136 | 136 |
|
| 137 | + @Test |
| 138 | + public void testDecodeLineWithOnlyCodeAndNoSeparator() { |
| 139 | + final EmbeddedChannel channel = newChannel(); |
| 140 | + // A line consisting of just the 3-digit code (no separator, no detail) must be rejected as an invalid |
| 141 | + // line rather than crash the decoder: ByteToMessageDecoder wraps any *unexpected* exception thrown out |
| 142 | + // of decode() (e.g. an IndexOutOfBoundsException from reading past the line) into a DecoderException |
| 143 | + // with that exception as its cause, whereas the intentional "invalid line" rejection path throws a |
| 144 | + // DecoderException with no cause. Asserting there is no cause distinguishes the two. |
| 145 | + DecoderException exception = assertThrows(DecoderException.class, new Executable() { |
| 146 | + @Override |
| 147 | + public void execute() { |
| 148 | + channel.writeInbound(newBuffer("250\r\n")); |
| 149 | + } |
| 150 | + }); |
| 151 | + assertNull(exception.getCause()); |
| 152 | + channel.finishAndReleaseAll(); |
| 153 | + } |
| 154 | + |
137 | 155 | @Test |
138 | 156 | public void testDecodeInvalidLine() { |
139 | 157 | final EmbeddedChannel channel = newChannel(); |
|