GeezerVison is showing github.com — Reject invalid content-length in PUSH_PROMISE with a stream error (#1… · netty/netty@a143321
File treeExpand file treeCollapse file tree Open diff view settings main/java/io/netty/handler/codec/http2 test/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/DefaultHttp2ConnectionDecoder.java +8-1Lines changed: 8 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -669,7 +669,14 @@ public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, int promi | 669 | 669 | // extract the content-length header | 670 | 670 | List<? extends CharSequence> contentLength = headers.getAll(HttpHeaderNames.CONTENT_LENGTH); | 671 | 671 | if (contentLength != null && !contentLength.isEmpty()) { | 672 | | - long cLength = HttpUtil.normalizeAndGetContentLength(contentLength, false, true); | | 672 | + long cLength; | | 673 | + try { | | 674 | + cLength = HttpUtil.normalizeAndGetContentLength(contentLength, false, true); | | 675 | + } catch (IllegalArgumentException e) { | | 676 | + throw streamError(promisedStreamId, PROTOCOL_ERROR, e, | | 677 | + "Promised request on stream %d for promised stream %d contains invalid content-length header", | | 678 | + streamId, promisedStreamId); | | 679 | + } | 673 | 680 | if (cLength != -1 && cLength != 0) { | 674 | 681 | throw streamError(promisedStreamId, PROTOCOL_ERROR, | 675 | 682 | "Promised request on stream %d for promised stream %d contains invalid content-length header", | |
Collapse file Copy file name to clipboardExpand all lines: codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2ConnectionDecoderTest.java +18Lines changed: 18 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -964,6 +964,24 @@ public void testPromiseWithContentLengthOfZero() throws Exception { | 964 | 964 | verify(listener).onPushPromiseRead(eq(ctx), eq(STREAM_ID), eq(PUSH_STREAM_ID), eq(headers), eq(0)); | 965 | 965 | } | 966 | 966 |
| | 967 | + @ParameterizedTest | | 968 | + @ValueSource(strings = {"abc", "1,2", "99999999999999999999"}) | | 969 | + public void testPromiseWithInvalidContentLength(String contentLength) throws Exception { | | 970 | + final Http2FrameListener dec = decode(); | | 971 | + final Http2Headers headers = new DefaultHttp2Headers(false) | | 972 | + .method("GET").scheme("https").authority("example.org").path("/") | | 973 | + .set(HttpHeaderNames.CONTENT_LENGTH, contentLength); | | 974 | + Http2Exception ex = assertThrows(Http2Exception.class, new Executable() { | | 975 | + @Override | | 976 | + public void execute() throws Throwable { | | 977 | + dec.onPushPromiseRead(ctx, STREAM_ID, PUSH_STREAM_ID, headers, 0); | | 978 | + } | | 979 | + }); | | 980 | + assertEquals(PROTOCOL_ERROR, ex.error()); | | 981 | + assertEquals(PUSH_STREAM_ID, Http2Exception.streamId(ex)); | | 982 | + verify(listener, never()).onPushPromiseRead(eq(ctx), anyInt(), anyInt(), any(Http2Headers.class), anyInt()); | | 983 | + } | | 984 | + | 967 | 985 | @Test | 968 | 986 | public void priorityReadAfterGoAwaySentShouldAllowFramesForStreamCreatedByLocalEndpoint() throws Exception { | 969 | 987 | mockGoAwaySentShouldAllowFramesForStreamCreatedByLocalEndpoint(); | |
|