Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,8 @@ private static bool IsHuffmanEncoded(byte b)

private void OnIndexedHeaderName(int index)
{
ThrowIfInvalidStaticIndex(index);

_headerStaticIndex = index;
_state = State.HeaderValueLength;
}
Expand Down Expand Up @@ -751,10 +753,20 @@ private void OnRequiredInsertCount(int requiredInsertCount)

private void OnIndexedHeaderField(int index, IHttpStreamHeadersHandler handler)
{
ThrowIfInvalidStaticIndex(index);

handler.OnStaticIndexedHeader(index);
_state = State.CompressedHeaders;
}

private static void ThrowIfInvalidStaticIndex(int index)
{
if (index >= H3StaticTable.Count)
{
throw new QPackDecodingException(SR.Format(SR.net_http_qpack_invalid_index, index));
}
}

private static void ThrowDynamicTableNotSupported()
{
throw new QPackDecodingException(SR.net_http_qpack_no_dynamic_table);
Expand Down
3 changes: 3 additions & 0 deletions src/libraries/Common/src/System/Net/Http/aspnetcore/SR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@
<data name="net_http_invalid_header_name" xml:space="preserve">
<value>Received an invalid header name: '{0}'.</value>
</data>
<data name="net_http_qpack_invalid_index" xml:space="preserve">
<value>Invalid header index: {0} is outside of the static table.</value>
</data>
<data name="net_http_qpack_no_dynamic_table" xml:space="preserve">
<value>No dynamic table support</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,20 @@ public void DecodesIncompleteHeaderBlock_Error(byte[] encoded)
Assert.Empty(_handler.DecodedHeaders);
}

[Theory]
// Indexed Field Line - Static Table - Index 99 (out of range)
[InlineData(new byte[] { 0xff, 0x24 }, 99)]
// Literal Header Field With Name Reference - Static Table - Index 99 (out of range)
[InlineData(new byte[] { 0x5f, 0x54, 0x01, 0x61 }, 99)]
public void DecodesIndexOutsideStaticTable_Error(byte[] encoded, int index)
{
_decoder.Decode([0x00, 0x00], endHeaders: false, handler: _handler);

var exception = Assert.Throws<QPackDecodingException>(() => _decoder.Decode(encoded, endHeaders: true, handler: _handler));
Assert.Equal(SR.Format(SR.net_http_qpack_invalid_index, index), exception.Message);
Assert.Empty(_handler.DecodedHeaders);
}

private static void TestDecodeWithoutIndexing(byte[] encoded, string expectedHeaderName, string expectedHeaderValue)
{
KeyValuePair<string, string>[] expectedValues = new[] { new KeyValuePair<string, string>(expectedHeaderName, expectedHeaderValue) };
Expand Down
3 changes: 3 additions & 0 deletions src/libraries/System.Net.Http/src/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,9 @@
<data name="net_http_content_write_larger_than_content_length" xml:space="preserve">
<value>Unable to write content to request stream; content would exceed Content-Length.</value>
</data>
<data name="net_http_qpack_invalid_index" xml:space="preserve">
<value>The HTTP/3 server attempted to reference the static table index {0}, which does not exist.</value>
</data>
<data name="net_http_qpack_no_dynamic_table" xml:space="preserve">
<value>The HTTP/3 server attempted to reference a dynamic table index that does not exist.</value>
</data>
Expand Down