GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Auto-port 5.0: Fix parsing HTTP chunks with multiple extensions (#16587) · netty/netty@d83abb5

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-http/src
    • main/java/io/netty/handler/codec/http
      • HttpChunkLineValidatingByteProcessor.java
    • test/java/io/netty/handler/codec/http
      • HttpRequestDecoderTest.java
      • HttpResponseDecoderTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-http/src/main/java/io/netty/handler/codec/http/HttpChunkLineValidatingByteProcessor.java‎

Copy file name to clipboardExpand all lines: codec-http/src/main/java/io/netty/handler/codec/http/HttpChunkLineValidatingByteProcessor.java
+12-4Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private enum State {
108108
new Match(CHUNK_EXT_VAL_QUOTED).chars("\""),
109109
new Match(CHUNK_EXT_VAL_TOKEN)
110110
.range(0x21, 0x7E)
111-
.chars("(),/:<=>?@[\\]{}", false)),
111+
.chars("(),/:<=>?@[\\]{}\"", false)),
112112
ChunkExtValQuoted(
113113
new Match(CHUNK_EXT_VAL_QUOTED_ESCAPE).chars("\\"),
114114
new Match(CHUNK_EXT_VAL_QUOTED_END).chars("\""),
@@ -128,7 +128,7 @@ private enum State {
128128
ChunkExtValToken(
129129
new Match(CHUNK_EXT_VAL_TOKEN)
130130
.range(0x21, 0x7E, true)
131-
.chars("(),/:<=>?@[\\]{}", false),
131+
.chars("(),/:<=>?@[\\]{};", false),
132132
new Match(CHUNK_EXT_NAME).chars(";")),
133133
;
134134

@@ -163,8 +163,16 @@ public boolean process(byte value) {
163163
}
164164

165165
public void finish() {
166-
if (state != State.Size && state != State.ChunkExtName && state != State.ChunkExtValQuotedEnd) {
167-
throw new InvalidChunkExtensionException("Invalid chunk extension");
166+
switch (state) {
167+
case ChunkExtValQuoted:
168+
case ChunkExtValQuotedEscape:
169+
case ChunkExtValStart:
170+
throw new InvalidChunkExtensionException("Invalid chunk extension");
168171
}
172+
// Exhaustiveness check
173+
assert state == State.Size ||
174+
state == State.ChunkExtName ||
175+
state == State.ChunkExtValQuotedEnd ||
176+
state == State.ChunkExtValToken;
169177
}
170178
}
Collapse file

‎codec-http/src/test/java/io/netty/handler/codec/http/HttpRequestDecoderTest.java‎

Copy file name to clipboardExpand all lines: codec-http/src/test/java/io/netty/handler/codec/http/HttpRequestDecoderTest.java
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,35 @@ void mustParseChunkExtensionsWithQuotedStringsAndEscapes() throws Exception {
863863
assertFalse(channel.finish()); // And there are no other chunks parsed.
864864
}
865865

866+
@Test
867+
void mustParseMultipleChunkExtensionsWithTokenValues() throws Exception {
868+
// Regression: the old Match-based state machine had ';' (0x3B) missing from the
869+
// exclusion set in ChunkExtValToken, so ';' was treated as a token character
870+
// instead of starting a new extension. This caused valid multi-extension lines
871+
// like ";name1=val1;name2=val2" to be rejected with InvalidChunkExtensionException.
872+
String requestStr = "GET / HTTP/1.1\r\n" +
873+
"Host: localhost\r\n" +
874+
"Transfer-Encoding: chunked\r\n\r\n" +
875+
"1;name1=val1;name2=val2\r\n" +
876+
"Y\r\n" +
877+
"0\r\n" +
878+
"\r\n";
879+
EmbeddedChannel channel = new EmbeddedChannel(new HttpRequestDecoder());
880+
assertTrue(channel.writeInbound(Unpooled.copiedBuffer(requestStr, CharsetUtil.US_ASCII)));
881+
HttpRequest request = channel.readInbound();
882+
assertFalse(request.decoderResult().isFailure());
883+
HttpContent content = channel.readInbound();
884+
if (content.decoderResult().isFailure()) {
885+
content.decoderResult().cause().printStackTrace();
886+
}
887+
assertFalse(content.decoderResult().isFailure()); // Must accept valid multi-extension token values.
888+
content.release();
889+
LastHttpContent last = channel.readInbound();
890+
assertEquals(0, last.content().readableBytes());
891+
last.release();
892+
assertFalse(channel.finish());
893+
}
894+
866895
@Test
867896
void mustRejectChunkExtensionsWithEscapedLineBreakInQuotedStrings() throws Exception {
868897
// See full explanation: https://w4ke.info/2025/10/29/funky-chunks-2.html
Collapse file

‎codec-http/src/test/java/io/netty/handler/codec/http/HttpResponseDecoderTest.java‎

Copy file name to clipboardExpand all lines: codec-http/src/test/java/io/netty/handler/codec/http/HttpResponseDecoderTest.java
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,32 @@ void mustParsedChunkExtensionsWithQuotedStringsAndEscapes() throws Exception {
11801180
assertFalse(channel.finish()); // And there are no other chunks parsed.
11811181
}
11821182

1183+
@Test
1184+
void mustParseMultipleChunkExtensionsWithTokenValues() throws Exception {
1185+
// Regression: the old Match-based state machine had ';' (0x3B) missing from the
1186+
// exclusion set in ChunkExtValToken, so ';' was treated as a token character
1187+
// instead of starting a new extension. This caused valid multi-extension lines
1188+
// like ";name1=val1;name2=val2" to be rejected with InvalidChunkExtensionException.
1189+
String responseStr = "HTTP/1.1 200 OK\r\n" +
1190+
"Transfer-Encoding: chunked\r\n" +
1191+
"\r\n" +
1192+
"1;name1=val1;name2=val2\r\n" +
1193+
"Y\r\n" +
1194+
"0\r\n" +
1195+
"\r\n";
1196+
EmbeddedChannel channel = new EmbeddedChannel(new HttpResponseDecoder());
1197+
assertTrue(channel.writeInbound(Unpooled.copiedBuffer(responseStr, CharsetUtil.US_ASCII)));
1198+
HttpResponse response = channel.readInbound();
1199+
assertFalse(response.decoderResult().isFailure());
1200+
HttpContent content = channel.readInbound();
1201+
assertFalse(content.decoderResult().isFailure()); // Must accept valid multi-extension token values.
1202+
content.release();
1203+
LastHttpContent last = channel.readInbound();
1204+
assertEquals(0, last.content().readableBytes());
1205+
last.release();
1206+
assertFalse(channel.finish());
1207+
}
1208+
11831209
@Test
11841210
void mustRejectChunkExtensionsWithEscapedLineBreakInQuotedStrings() throws Exception {
11851211
// See full explanation: https://w4ke.info/2025/10/29/funky-chunks-2.html

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.