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:
parent
8d7ffec081
commit
f7795c81a5
@ -287,7 +287,6 @@ public class DefaultHttp2FrameReader implements Http2FrameReader, Http2FrameSize
|
|||||||
private void verifyDataFrame() throws Http2Exception {
|
private void verifyDataFrame() throws Http2Exception {
|
||||||
verifyAssociatedWithAStream();
|
verifyAssociatedWithAStream();
|
||||||
verifyNotProcessingHeaders();
|
verifyNotProcessingHeaders();
|
||||||
verifyPayloadLength(payloadLength);
|
|
||||||
|
|
||||||
if (payloadLength < flags.getPaddingPresenceFieldLength()) {
|
if (payloadLength < flags.getPaddingPresenceFieldLength()) {
|
||||||
throw streamError(streamId, FRAME_SIZE_ERROR,
|
throw streamError(streamId, FRAME_SIZE_ERROR,
|
||||||
@ -298,7 +297,6 @@ public class DefaultHttp2FrameReader implements Http2FrameReader, Http2FrameSize
|
|||||||
private void verifyHeadersFrame() throws Http2Exception {
|
private void verifyHeadersFrame() throws Http2Exception {
|
||||||
verifyAssociatedWithAStream();
|
verifyAssociatedWithAStream();
|
||||||
verifyNotProcessingHeaders();
|
verifyNotProcessingHeaders();
|
||||||
verifyPayloadLength(payloadLength);
|
|
||||||
|
|
||||||
int requiredLength = flags.getPaddingPresenceFieldLength() + flags.getNumPriorityBytes();
|
int requiredLength = flags.getPaddingPresenceFieldLength() + flags.getNumPriorityBytes();
|
||||||
if (payloadLength < requiredLength) {
|
if (payloadLength < requiredLength) {
|
||||||
@ -328,7 +326,6 @@ public class DefaultHttp2FrameReader implements Http2FrameReader, Http2FrameSize
|
|||||||
|
|
||||||
private void verifySettingsFrame() throws Http2Exception {
|
private void verifySettingsFrame() throws Http2Exception {
|
||||||
verifyNotProcessingHeaders();
|
verifyNotProcessingHeaders();
|
||||||
verifyPayloadLength(payloadLength);
|
|
||||||
if (streamId != 0) {
|
if (streamId != 0) {
|
||||||
throw connectionError(PROTOCOL_ERROR, "A stream ID must be zero.");
|
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 {
|
private void verifyPushPromiseFrame() throws Http2Exception {
|
||||||
verifyNotProcessingHeaders();
|
verifyNotProcessingHeaders();
|
||||||
verifyPayloadLength(payloadLength);
|
|
||||||
|
|
||||||
// Subtract the length of the promised stream ID field, to determine the length of the
|
// Subtract the length of the promised stream ID field, to determine the length of the
|
||||||
// rest of the payload (header block fragment + payload).
|
// rest of the payload (header block fragment + payload).
|
||||||
@ -366,7 +362,6 @@ public class DefaultHttp2FrameReader implements Http2FrameReader, Http2FrameSize
|
|||||||
|
|
||||||
private void verifyGoAwayFrame() throws Http2Exception {
|
private void verifyGoAwayFrame() throws Http2Exception {
|
||||||
verifyNotProcessingHeaders();
|
verifyNotProcessingHeaders();
|
||||||
verifyPayloadLength(payloadLength);
|
|
||||||
|
|
||||||
if (streamId != 0) {
|
if (streamId != 0) {
|
||||||
throw connectionError(PROTOCOL_ERROR, "A stream ID must be zero.");
|
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 {
|
private void verifyContinuationFrame() throws Http2Exception {
|
||||||
verifyAssociatedWithAStream();
|
verifyAssociatedWithAStream();
|
||||||
verifyPayloadLength(payloadLength);
|
|
||||||
|
|
||||||
if (headersContinuation == null) {
|
if (headersContinuation == null) {
|
||||||
throw connectionError(PROTOCOL_ERROR, "Received %s frame but not currently processing headers.",
|
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 {
|
private void verifyAssociatedWithAStream() throws Http2Exception {
|
||||||
if (streamId == 0) {
|
if (streamId == 0) {
|
||||||
throw connectionError(PROTOCOL_ERROR, "Frame of type %s must be associated with a stream.", frameType);
|
throw connectionError(PROTOCOL_ERROR, "Frame of type %s must be associated with a stream.", frameType);
|
||||||
|
Loading…
Reference in New Issue
Block a user