From 120fb6fcdf1c689fa13d5751487459cb278e6cc2 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 1a280509ea..f029a4484f 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 @@ -283,7 +283,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, @@ -294,7 +293,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) { @@ -324,7 +322,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."); } @@ -338,7 +335,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). @@ -362,7 +358,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."); @@ -383,7 +378,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.", @@ -767,12 +761,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);