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: Reset UTF-8 decode state on CR in StompSubframeDecoder… · netty/netty@d5bdf36

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-stomp/src
    • main/java/io/netty/handler/codec/stomp
      • StompSubframeDecoder.java
    • test/java/io/netty/handler/codec/stomp
      • StompSubframeDecoderTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-stomp/src/main/java/io/netty/handler/codec/stomp/StompSubframeDecoder.java‎

Copy file name to clipboardExpand all lines: codec-stomp/src/main/java/io/netty/handler/codec/stomp/StompSubframeDecoder.java
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ AppendableCharSequence charSequence() {
304304
@Override
305305
public boolean process(byte nextByte) throws Exception {
306306
if (nextByte == StompConstants.CR) {
307+
interim = 0;
308+
nextRead = false;
307309
++lineLength;
308310
return true;
309311
}
Collapse file

‎codec-stomp/src/test/java/io/netty/handler/codec/stomp/StompSubframeDecoderTest.java‎

Copy file name to clipboardExpand all lines: codec-stomp/src/test/java/io/netty/handler/codec/stomp/StompSubframeDecoderTest.java
+53Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,4 +443,57 @@ void testInvalidEscapeHeadersSequence() throws Exception {
443443
assertEquals("received an invalid escape header sequence 'custom_invalid\\t'",
444444
headersSubFrame.decoderResult().cause().getMessage());
445445
}
446+
447+
@Test
448+
public void testCRResetsUtf8DecodeState() throws Exception {
449+
// When a CR byte appears during a multi-byte UTF-8 sequence, the parser's interim state
450+
// should be cleared so that subsequent bytes are decoded correctly.
451+
// Bug: CR is skipped without resetting interim/nextRead, so the next byte gets
452+
// incorrectly combined with dirty UTF-8 state, producing garbage characters.
453+
//
454+
// Craft a header value where:
455+
// - 0xC3 starts a 2-byte UTF-8 sequence (sets interim)
456+
// - 0x0D (CR) is skipped but should clear interim state
457+
// - 0x41 ('A') should be decoded as plain ASCII 'A', not combined with dirty interim
458+
channel = new EmbeddedChannel(new StompSubframeDecoder());
459+
460+
ByteBuf incoming = Unpooled.buffer();
461+
// CONNECT command line
462+
incoming.writeBytes("CONNECT\r\n".getBytes(UTF_8));
463+
// header with multi-byte UTF-8 start byte (0xC3), then CR, then ASCII 'A'
464+
incoming.writeByte((byte) 'h');
465+
incoming.writeByte((byte) 'e');
466+
incoming.writeByte((byte) 'a');
467+
incoming.writeByte((byte) 'd');
468+
incoming.writeByte((byte) 'e');
469+
incoming.writeByte((byte) 'r');
470+
incoming.writeByte((byte) ':');
471+
// 0xC3 starts a 2-byte UTF-8 sequence - sets interim state
472+
incoming.writeByte((byte) 0xC3);
473+
// CR (0x0D) - should be skipped AND clear the interim UTF-8 state
474+
incoming.writeByte((byte) 0x0D);
475+
// 'A' - should be decoded as plain 'A' since CR should have reset state
476+
incoming.writeByte((byte) 'A');
477+
// end of header line
478+
incoming.writeByte((byte) '\n');
479+
// empty line to end headers
480+
incoming.writeByte((byte) '\n');
481+
// null byte to end frame
482+
incoming.writeByte((byte) '\0');
483+
484+
assertTrue(channel.writeInbound(incoming));
485+
486+
StompHeadersSubframe frame = channel.readInbound();
487+
assertNotNull(frame);
488+
assertEquals(StompCommand.CONNECT, frame.command());
489+
// The header value should be just "A" (CR is skipped, UTF-8 state reset)
490+
// With the bug, it would contain corrupted UTF-8 combining 0xC3 with 'A'
491+
assertEquals("A", frame.headers().get("header"));
492+
493+
StompContentSubframe content = channel.readInbound();
494+
assertSame(LastStompContentSubframe.EMPTY_LAST_CONTENT, content);
495+
content.release();
496+
497+
assertNull(channel.readInbound());
498+
}
446499
}

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.