From f7795c81a5f32021f77c0d8117866d92c1173e03 Mon Sep 17 00:00:00 2001 From: Liyuan Date: Mon, 19 Apr 2021 20:01:45 -0700 Subject: [PATCH] Remove duplicate HTTP2 payload length check against max frame size Motivation: In the method processHeaderState(), we have checked the http2 payload length against max frame size. But later for different types of frames, we checked this again. Modifications: Removed the duplicate check in verify*() methods. And removed verifyPayloadLength() method, since it will not be used anymore. Result: Remove duplicate check and make the code cleaner. --- .../handler/codec/http2/DefaultHttp2FrameReader.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2FrameReader.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2FrameReader.java index f9d1fcc7a2..a2453faf05 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2FrameReader.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2FrameReader.java @@ -287,7 +287,6 @@ public class DefaultHttp2FrameReader implements Http2FrameReader, Http2FrameSize private void verifyDataFrame() throws Http2Exception { verifyAssociatedWithAStream(); verifyNotProcessingHeaders(); - verifyPayloadLength(payloadLength); if (payloadLength < flags.getPaddingPresenceFieldLength()) { throw streamError(streamId, FRAME_SIZE_ERROR, @@ -298,7 +297,6 @@ public class DefaultHttp2FrameReader implements Http2FrameReader, Http2FrameSize private void verifyHeadersFrame() throws Http2Exception { verifyAssociatedWithAStream(); verifyNotProcessingHeaders(); - verifyPayloadLength(payloadLength); int requiredLength = flags.getPaddingPresenceFieldLength() + flags.getNumPriorityBytes(); if (payloadLength < requiredLength) { @@ -328,7 +326,6 @@ public class DefaultHttp2FrameReader implements Http2FrameReader, Http2FrameSize private void verifySettingsFrame() throws Http2Exception { verifyNotProcessingHeaders(); - verifyPayloadLength(payloadLength); if (streamId != 0) { throw connectionError(PROTOCOL_ERROR, "A stream ID must be zero."); } @@ -342,7 +339,6 @@ public class DefaultHttp2FrameReader implements Http2FrameReader, Http2FrameSize private void verifyPushPromiseFrame() throws Http2Exception { verifyNotProcessingHeaders(); - verifyPayloadLength(payloadLength); // Subtract the length of the promised stream ID field, to determine the length of the // rest of the payload (header block fragment + payload). @@ -366,7 +362,6 @@ public class DefaultHttp2FrameReader implements Http2FrameReader, Http2FrameSize private void verifyGoAwayFrame() throws Http2Exception { verifyNotProcessingHeaders(); - verifyPayloadLength(payloadLength); if (streamId != 0) { throw connectionError(PROTOCOL_ERROR, "A stream ID must be zero."); @@ -387,7 +382,6 @@ public class DefaultHttp2FrameReader implements Http2FrameReader, Http2FrameSize private void verifyContinuationFrame() throws Http2Exception { verifyAssociatedWithAStream(); - verifyPayloadLength(payloadLength); if (headersContinuation == null) { throw connectionError(PROTOCOL_ERROR, "Received %s frame but not currently processing headers.", @@ -771,12 +765,6 @@ public class DefaultHttp2FrameReader implements Http2FrameReader, Http2FrameSize } } - private void verifyPayloadLength(int payloadLength) throws Http2Exception { - if (payloadLength > maxFrameSize) { - throw connectionError(PROTOCOL_ERROR, "Total payload length %d exceeds max frame length.", payloadLength); - } - } - private void verifyAssociatedWithAStream() throws Http2Exception { if (streamId == 0) { throw connectionError(PROTOCOL_ERROR, "Frame of type %s must be associated with a stream.", frameType);