diff --git a/src/Shared/test/Shared.Tests/runtime/Http2/HPackDecoderTest.cs b/src/Shared/test/Shared.Tests/runtime/Http2/HPackDecoderTest.cs index ff141b846b39..2dde54407bcd 100644 --- a/src/Shared/test/Shared.Tests/runtime/Http2/HPackDecoderTest.cs +++ b/src/Shared/test/Shared.Tests/runtime/Http2/HPackDecoderTest.cs @@ -151,6 +151,25 @@ public void DecodesIndexedHeaderField_DynamicTable() Assert.Equal(_headerValueString, _handler.DecodedHeaders[_headerNameString]); } + [Fact] + public void DecodesIndexedHeaderField_DynamicTable_ReferencedEntryRemovedOnInsertion() + { + // Pre-populate the dynamic table so we'll have something to reference. + // This entry will have index 62 (0x3E). + _dynamicTable.Insert(_headerNameBytes, _headerValueBytes); + Assert.Equal(1, _dynamicTable.Count); + + Assert.InRange(_dynamicTable.MaxSize, 1, _literalHeaderNameBytes.Length); // Assert that our string will be too big + + byte[] encoded = (new byte[] { 0x40 | 0x3E }) // Indexing enabled (0x40) | dynamic table (62 = 0x3E) as a 6-integer, + .Concat(_literalHeaderName) // A header value that's too large to fit in the dynamic table + .ToArray(); + + _decoder.Decode(encoded, endHeaders: true, handler: _handler); + Assert.Equal(0, _dynamicTable.Count); // The large entry caused the table to be wiped + Assert.Equal(_literalHeaderNameString, _handler.DecodedHeaders[_headerNameString]); // but we got the header anyway + } + [Fact] public void DecodesIndexedHeaderField_OutOfRange_Error() {