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 — 5.0 port: Fix IndexOutOfBoundsException in StompSubframeDecoder on he… · netty/netty@28db032

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-stomp/src/test/java/io/netty/handler/codec/stomp
    • StompSubframeDecoderTest.java
Expand file treeCollapse file tree
Open diff view settings
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
+112Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,118 @@ void testNotUnescapeHeadersForConnectedCommand() throws Exception {
317317
assertNull(obj);
318318
}
319319

320+
@Test
321+
public void testHeartbeatOnlyDoesNotThrowException() throws Exception {
322+
// STOMP heartbeat is just a LF byte - should not cause IndexOutOfBoundsException
323+
ByteBuf heartbeat = Unpooled.buffer();
324+
heartbeat.writeByte('\n');
325+
channel.writeInbound(heartbeat);
326+
327+
// Heartbeat should be consumed silently, no output produced
328+
Object result = channel.readInbound();
329+
assertNull(result);
330+
}
331+
332+
@Test
333+
public void testMultipleHeartbeatsDoNotThrowException() throws Exception {
334+
// Multiple consecutive heartbeats
335+
ByteBuf heartbeats = Unpooled.buffer();
336+
heartbeats.writeByte('\n');
337+
heartbeats.writeByte('\n');
338+
heartbeats.writeByte('\n');
339+
channel.writeInbound(heartbeats);
340+
341+
Object result = channel.readInbound();
342+
assertNull(result);
343+
}
344+
345+
@Test
346+
public void testCarriageReturnLineFeedHeartbeat() throws Exception {
347+
// CR+LF heartbeat
348+
ByteBuf heartbeat = Unpooled.buffer();
349+
heartbeat.writeByte('\r');
350+
heartbeat.writeByte('\n');
351+
channel.writeInbound(heartbeat);
352+
353+
Object result = channel.readInbound();
354+
assertNull(result);
355+
}
356+
357+
@Test
358+
public void testHeartbeatFollowedByFrame() throws Exception {
359+
// Heartbeat bytes followed by a real STOMP frame should decode correctly
360+
ByteBuf incoming = Unpooled.buffer();
361+
incoming.writeByte('\n');
362+
incoming.writeByte('\n');
363+
incoming.writeBytes(StompTestConstants.CONNECT_FRAME.getBytes());
364+
channel.writeInbound(incoming);
365+
366+
StompHeadersSubframe frame = channel.readInbound();
367+
assertNotNull(frame);
368+
assertEquals(StompCommand.CONNECT, frame.command());
369+
370+
StompContentSubframe content = channel.readInbound();
371+
assertSame(LastStompContentSubframe.EMPTY_LAST_CONTENT, content);
372+
content.release();
373+
374+
assertNull(channel.readInbound());
375+
}
376+
377+
@Test
378+
public void testHeartbeatBetweenFrames() throws Exception {
379+
// Heartbeat bytes between two STOMP frames
380+
ByteBuf incoming = Unpooled.buffer();
381+
incoming.writeBytes(StompTestConstants.CONNECT_FRAME.getBytes());
382+
incoming.writeByte('\n');
383+
incoming.writeByte('\n');
384+
incoming.writeBytes(StompTestConstants.CONNECTED_FRAME.getBytes());
385+
channel.writeInbound(incoming);
386+
387+
StompHeadersSubframe frame1 = channel.readInbound();
388+
assertNotNull(frame1);
389+
assertEquals(StompCommand.CONNECT, frame1.command());
390+
391+
StompContentSubframe content1 = channel.readInbound();
392+
assertSame(LastStompContentSubframe.EMPTY_LAST_CONTENT, content1);
393+
content1.release();
394+
395+
StompHeadersSubframe frame2 = channel.readInbound();
396+
assertNotNull(frame2);
397+
assertEquals(StompCommand.CONNECTED, frame2.command());
398+
399+
StompContentSubframe content2 = channel.readInbound();
400+
assertSame(LastStompContentSubframe.EMPTY_LAST_CONTENT, content2);
401+
content2.release();
402+
403+
assertNull(channel.readInbound());
404+
}
405+
406+
@Test
407+
public void testHeartbeatSentSeparatelyThenFrame() throws Exception {
408+
// Simulate heartbeat arriving in a separate TCP segment, then a frame later
409+
ByteBuf heartbeat = Unpooled.buffer();
410+
heartbeat.writeByte('\n');
411+
channel.writeInbound(heartbeat);
412+
413+
// No output from heartbeat
414+
assertNull(channel.readInbound());
415+
416+
// Now send a real frame
417+
ByteBuf frame = Unpooled.buffer();
418+
frame.writeBytes(StompTestConstants.CONNECT_FRAME.getBytes());
419+
channel.writeInbound(frame);
420+
421+
StompHeadersSubframe headersSubframe = channel.readInbound();
422+
assertNotNull(headersSubframe);
423+
assertEquals(StompCommand.CONNECT, headersSubframe.command());
424+
425+
StompContentSubframe content = channel.readInbound();
426+
assertSame(LastStompContentSubframe.EMPTY_LAST_CONTENT, content);
427+
content.release();
428+
429+
assertNull(channel.readInbound());
430+
}
431+
320432
@Test
321433
void testInvalidEscapeHeadersSequence() throws Exception {
322434
channel = new EmbeddedChannel(new StompSubframeDecoder(true));

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.