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 4.1: Http2: reject generic frames whose payload exceeds SETTINGS_MAX_FRAME_SIZE by netty-project-bot · Pull Request #18000 · netty/netty

Auto-port 4.1: Http2: reject generic frames whose payload exceeds SETTINGS_MAX_FRAME_SIZE #18000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
normanmaurer merged 1 commit into 4.1 from auto-port-pr-17779-to-4.1
Oct 22, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

Auto-port 4.1: Http2: reject generic frames whose payload exceeds SETTINGS_MAX_FRAME_SIZE #18000

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
85eae30
Http2: reject generic frames whose payload exceeds SETTINGS_MAX_FRAME…
AbhishekShukla1289 Oct 22, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Http2: reject generic frames whose payload exceeds SETTINGS_MAX_FRAME…
…_SIZE (#17779)

Motivation:

RFC 9113 Section 4.2 applies SETTINGS_MAX_FRAME_SIZE to the payload
of every frame. The typed writers in DefaultHttp2FrameWriter honour
the limit advertised by the remote peer: writeData splits large
payloads into multiple DATA frames and writeHeaders uses CONTINUATION.
The generic writeFrame(...) path does not check the limit and writes
the full payload length into a single frame header, so it can emit a
frame that a compliant peer must reject with FRAME_SIZE_ERROR.

Modification:

- Verify the payload length against maxFrameSize in writeFrame before
  allocating the frame header. A generic frame has unknown semantics
  and cannot be split, so the write fails instead: the payload is
  released and the promise is failed with an IllegalArgumentException,
  consistent with the other verify* checks in this class.
- Add tests for a payload of maxFrameSize + 1 (rejected, nothing
  written, payload released) and of exactly maxFrameSize (written).
  The first fails without the change and passes with it.

Result:

Generic frames can no longer exceed the frame size negotiated with
the remote peer. codec-http2 tests: 1633, 0 failures.

Fixes #17426

---------

Co-authored-by: Netty Project Bot <[email protected]>
Co-authored-by: Norman Maurer <[email protected]>
Co-authored-by: Bryce Anderson <[email protected]>
(cherry picked from commit dc5655e)
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@AbhishekShukla1289 @netty-project-bot
@normanmaurer @bryce-anderson
4 people committed Oct 22, 2026
commit 85eae30bb31034455d2388207e3dedb16d02fef3

There are no files selected for viewing

25 changes: 25 additions & 0 deletions 25 codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2FrameWriter.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import io.netty.handler.codec.http2.Http2FrameWriter.Configuration;
import io.netty.handler.codec.http2.Http2HeadersEncoder.SensitivityDetector;
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;

import static io.netty.buffer.Unpooled.directBuffer;
import static io.netty.buffer.Unpooled.unreleasableBuffer;
Expand Down Expand Up @@ -71,6 +73,8 @@
* A {@link Http2FrameWriter} that supports all frame types defined by the HTTP/2 specification.
*/
public class DefaultHttp2FrameWriter implements Http2FrameWriter, Http2FrameSizePolicy, Configuration {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(DefaultHttp2FrameWriter.class);

private static final String STREAM_ID = "Stream ID";
private static final String STREAM_DEPENDENCY = "Stream Dependency";
/**
Expand Down Expand Up @@ -321,6 +325,7 @@ public ChannelFuture writeSettings(ChannelHandlerContext ctx, Http2Settings sett
try {
checkNotNull(settings, "settings");
int payloadLength = SETTING_ENTRY_LENGTH * settings.size();
verifyPayloadLength(SETTINGS, payloadLength);
ByteBuf buf = ctx.alloc().buffer(FRAME_HEADER_LENGTH + payloadLength);
writeFrameHeaderInternal(buf, payloadLength, SETTINGS, new Http2Flags(), 0);
for (Http2Settings.PrimitiveEntry<Long> entry : settings.entries()) {
Expand Down Expand Up @@ -427,6 +432,15 @@ public ChannelFuture writeGoAway(ChannelHandlerContext ctx, int lastStreamId, lo
verifyStreamOrConnectionId(lastStreamId, "Last Stream ID");
verifyErrorCode(errorCode);

// GOAWAY must still be sent, so instead of rejecting oversized debug data truncate it to fit into
// SETTINGS_MAX_FRAME_SIZE together with the 8 bytes of last stream id and error code.
int maxDebugDataLength = maxFrameSize - 8;
if (debugData.readableBytes() > maxDebugDataLength) {
logger.warn("GOAWAY debug data of {} bytes exceeds the maximum of {} bytes allowed by " +
"SETTINGS_MAX_FRAME_SIZE, truncating it.", debugData.readableBytes(), maxDebugDataLength);
debugData = debugData.readSlice(maxDebugDataLength);
}

int payloadLength = 8 + debugData.readableBytes();
ByteBuf buf = ctx.alloc().buffer(GO_AWAY_FRAME_HEADER_LENGTH);
// Assume nothing below will throw until buf is written. That way we don't have to take care of ownership
Expand Down Expand Up @@ -476,6 +490,9 @@ public ChannelFuture writeFrame(ChannelHandlerContext ctx, byte frameType, int s
new SimpleChannelPromiseAggregator(promise, ctx.channel(), ctx.executor());
try {
verifyStreamOrConnectionId(streamId, STREAM_ID);
// RFC 9113 Section 4.2: SETTINGS_MAX_FRAME_SIZE applies to the payload of every frame. The semantics of
// a generic frame are unknown so it cannot be split, the write must fail instead.
verifyPayloadLength(frameType, payload.readableBytes());
ByteBuf buf = ctx.alloc().buffer(FRAME_HEADER_LENGTH);
// Assume nothing below will throw until buf is written. That way we don't have to take care of ownership
// in the catch block.
Expand Down Expand Up @@ -659,6 +676,14 @@ private static void verifyErrorCode(long errorCode) {
}
}

private void verifyPayloadLength(byte frameType, int payloadLength) {
if (payloadLength > maxFrameSize) {
throw new IllegalArgumentException("Payload length " + payloadLength + " of frame type 0x" +
Integer.toHexString(frameType & 0xFF) + " exceeds the maximum frame size " + maxFrameSize +
" advertised by the remote peer.");
}
}

private static void verifyWindowSizeIncrement(int windowSizeIncrement) {
checkPositiveOrZero(windowSizeIncrement, "windowSizeIncrement");
}
Expand Down
67 changes: 67 additions & 0 deletions 67 codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2FrameWriterTest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.*;

/**
Expand Down Expand Up @@ -356,6 +357,72 @@ public void writeFrameHasPayload() throws Exception {
assertEquals(expectedOutbound, outbound);
}

@Test
public void writeFrameExceedingMaxFrameSizeFailsPromiseAndReleasesPayload() throws Exception {
frameWriter.maxFrameSize(Http2CodecUtil.MAX_FRAME_SIZE_LOWER_BOUND);
ByteBuf payload = Unpooled.buffer().writeZero(Http2CodecUtil.MAX_FRAME_SIZE_LOWER_BOUND + 1);

ChannelFuture future = frameWriter.writeFrame(ctx, (byte) 0xf, 0, new Http2Flags(), payload, promise);

assertTrue(future.isDone());
assertFalse(future.isSuccess());
assertInstanceOf(IllegalArgumentException.class, future.cause());
assertTrue(future.cause().getMessage().contains("0xf"));
// Nothing must have been written and the payload must have been released
assertEquals(0, outbound.readableBytes());
assertEquals(0, payload.refCnt());
verify(ctx, never()).write(any(), any(ChannelPromise.class));
}

@Test
public void writeFrameAtMaxFrameSizeSucceeds() throws Exception {
frameWriter.maxFrameSize(Http2CodecUtil.MAX_FRAME_SIZE_LOWER_BOUND);
ByteBuf payload = Unpooled.buffer().writeZero(Http2CodecUtil.MAX_FRAME_SIZE_LOWER_BOUND);

ChannelFuture future = frameWriter.writeFrame(ctx, (byte) 0xf, 0, new Http2Flags(), payload, promise);

// The mocked context never completes the writes, so only verify that the write was not rejected
assertFalse(future.isDone() && !future.isSuccess());
assertEquals(Http2CodecUtil.FRAME_HEADER_LENGTH + Http2CodecUtil.MAX_FRAME_SIZE_LOWER_BOUND,
outbound.readableBytes());
// 24 bit payload length field must hold exactly the payload size
assertEquals(Http2CodecUtil.MAX_FRAME_SIZE_LOWER_BOUND, outbound.getUnsignedMedium(0));
}

@Test
public void writeSettingsExceedingMaxFrameSizeFailsPromise() throws Exception {
frameWriter.maxFrameSize(Http2CodecUtil.MAX_FRAME_SIZE_LOWER_BOUND);
Http2Settings settings = new Http2Settings();
// Each setting takes 6 bytes, so this is one entry more than fits into a single frame
int entries = Http2CodecUtil.MAX_FRAME_SIZE_LOWER_BOUND / Http2CodecUtil.SETTING_ENTRY_LENGTH + 1;
for (int i = 0; i < entries; i++) {
settings.put((char) (0x100 + i), Long.valueOf(0));
}

ChannelFuture future = frameWriter.writeSettings(ctx, settings, promise);

assertTrue(future.isDone());
assertFalse(future.isSuccess());
assertInstanceOf(IllegalArgumentException.class, future.cause());
assertTrue(future.cause().getMessage().contains("0x4"));
assertEquals(0, outbound.readableBytes());
}

@Test
public void writeGoAwayTruncatesDebugDataExceedingMaxFrameSize() throws Exception {
frameWriter.maxFrameSize(Http2CodecUtil.MAX_FRAME_SIZE_LOWER_BOUND);
ByteBuf debugData = Unpooled.buffer().writeZero(Http2CodecUtil.MAX_FRAME_SIZE_LOWER_BOUND);

frameWriter.writeGoAway(ctx, 0, Http2Error.NO_ERROR.code(), debugData, promise);

// 8 bytes of last stream id and error code plus the truncated debug data fill exactly one frame
assertEquals(Http2CodecUtil.MAX_FRAME_SIZE_LOWER_BOUND, outbound.getUnsignedMedium(0));
assertEquals(Http2CodecUtil.FRAME_HEADER_LENGTH + Http2CodecUtil.MAX_FRAME_SIZE_LOWER_BOUND,
outbound.readableBytes());
// The original debug data buffer must have been released
assertEquals(0, debugData.refCnt());
}

@Test
public void writePriority() {
frameWriter.writePriority(
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
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.