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.
This commit is contained in:
Liyuan 2021-04-19 20:01:45 -07:00 committed by Norman Maurer
parent 8d7ffec081
commit f7795c81a5

View File

@ -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);