Skip to content

Commit

Permalink
Fix h2spec test 4.3 about invalid header block
Browse files Browse the repository at this point in the history
Motivation:

HPackDecoder works on entire header block, we shouldn't encounter
incomplete header fields. If we do we should treat it as
a decoding error and according to the specification:

A decoding error in a header block MUST be treated as
a connection error (Section 5.4.1) of type COMPRESSION_ERROR.

Modifications:

* Check final state in HpackDecoder once we've decoded all the data.

Result:

* Throw a connection error if we receive incomplete header fields
* H2spec 4.3 tests all passes
  • Loading branch information
madgnome authored and Scottmitch committed Jan 18, 2018
1 parent 1740f36 commit 61dba95
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ public void decode(int streamId, ByteBuf in, Http2Headers headers) throws Http2E
if (headersLength > maxHeaderListSize) {
headerListSizeExceeded(streamId, maxHeaderListSize, true);
}

if (state != READ_HEADER_REPRESENTATION) {
throw connectionError(COMPRESSION_ERROR, "Incomplete header block fragment.");
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,4 +512,17 @@ public void testAccountForHeaderOverhead() throws Exception {
in.release();
}
}

@Test
public void testIncompleteHeaderFieldRepresentation() throws Http2Exception {
// Incomplete Literal Header Field with Incremental Indexing
byte[] input = {(byte) 0x40};
ByteBuf in = Unpooled.wrappedBuffer(input);
try {
expectedException.expect(Http2Exception.class);
hpackDecoder.decode(0, in, mockHeaders);
} finally {
in.release();
}
}
}
1 change: 0 additions & 1 deletion testsuite-http2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
<excludeSpecs>
<excludeSpec>3.8 - Sends a GOAWAY frame</excludeSpec>
<excludeSpec>4.2 - Sends a dynamic table size update at the end of header block</excludeSpec>
<excludeSpec>4.3 - Sends invalid header block fragment</excludeSpec>
<excludeSpec>5.1 - idle: Sends a DATA frame</excludeSpec>
<excludeSpec>5.1 - closed: Sends a DATA frame</excludeSpec>
<excludeSpec>5.1 - closed: Sends a HEADERS frame</excludeSpec>
Expand Down

0 comments on commit 61dba95

Please sign in to comment.