Skip to content

Commit 12c8cd8

Browse files
authored
Add some HPackDecoderTests for empty header names and values (#57032)
Sanity checking for https://www.cve.org/CVERecord?id=CVE-2019-9516
1 parent 1470e00 commit 12c8cd8

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

src/Shared/test/Shared.Tests/runtime/Http2/HPackDecoderTest.cs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ public class HPackDecoderTests
8787
.Concat(_headerValueHuffmanBytes)
8888
.ToArray();
8989

90+
private static readonly byte[] _literalEmptyString = new byte[] { 0x00 };
91+
92+
private static readonly byte[] _literalEmptyStringHuffman = new byte[] { 0x80 };
93+
9094
// & *
9195
// 11111000 11111111
9296
private static readonly byte[] _huffmanLongPadding = new byte[] { 0x82, 0xf8, 0xff };
@@ -243,6 +247,43 @@ public void DecodesLiteralHeaderFieldWithoutIndexing_NewName()
243247
TestDecodeWithoutIndexing(encoded, _headerNameString, _headerValueString);
244248
}
245249

250+
[Fact]
251+
public void DecodesLiteralHeaderFieldWithoutIndexing_NewName_EmptyName()
252+
{
253+
byte[] encoded = _literalHeaderFieldWithoutIndexingNewName
254+
.Concat(_literalEmptyString)
255+
.Concat(_headerValue)
256+
.ToArray();
257+
258+
HPackDecodingException exception = Assert.Throws<HPackDecodingException>(() => _decoder.Decode(encoded, endHeaders: true, handler: _handler));
259+
Assert.Equal(SR.Format(SR.net_http_invalid_header_name, string.Empty), exception.Message);
260+
Assert.Empty(_handler.DecodedHeaders);
261+
}
262+
263+
[Fact]
264+
public void DecodesLiteralHeaderFieldWithoutIndexing_NewName_EmptyValue()
265+
{
266+
byte[] encoded = _literalHeaderFieldWithoutIndexingNewName
267+
.Concat(_headerName)
268+
.Concat(_literalEmptyString)
269+
.ToArray();
270+
271+
TestDecodeWithoutIndexing(encoded, _headerNameString, string.Empty);
272+
}
273+
274+
[Fact]
275+
public void DecodesLiteralHeaderFieldWithoutIndexing_NewName_EmptyNameAndValue()
276+
{
277+
byte[] encoded = _literalHeaderFieldWithoutIndexingNewName
278+
.Concat(_literalEmptyString)
279+
.Concat(_literalEmptyString)
280+
.ToArray();
281+
282+
HPackDecodingException exception = Assert.Throws<HPackDecodingException>(() => _decoder.Decode(encoded, endHeaders: true, handler: _handler));
283+
Assert.Equal(SR.Format(SR.net_http_invalid_header_name, string.Empty), exception.Message);
284+
Assert.Empty(_handler.DecodedHeaders);
285+
}
286+
246287
[Fact]
247288
public void DecodesLiteralHeaderFieldWithoutIndexing_NewName_HuffmanEncodedName()
248289
{
@@ -254,6 +295,19 @@ public void DecodesLiteralHeaderFieldWithoutIndexing_NewName_HuffmanEncodedName(
254295
TestDecodeWithoutIndexing(encoded, _headerNameString, _headerValueString);
255296
}
256297

298+
[Fact]
299+
public void DecodesLiteralHeaderFieldWithoutIndexing_NewName_HuffmanEncodedName_Empty()
300+
{
301+
byte[] encoded = _literalHeaderFieldWithoutIndexingNewName
302+
.Concat(_literalEmptyStringHuffman)
303+
.Concat(_headerValue)
304+
.ToArray();
305+
306+
HPackDecodingException exception = Assert.Throws<HPackDecodingException>(() => _decoder.Decode(encoded, endHeaders: true, handler: _handler));
307+
Assert.Equal(SR.Format(SR.net_http_invalid_header_name, string.Empty), exception.Message);
308+
Assert.Empty(_handler.DecodedHeaders);
309+
}
310+
257311
[Fact]
258312
public void DecodesLiteralHeaderFieldWithoutIndexing_NewName_HuffmanEncodedValue()
259313
{
@@ -265,6 +319,17 @@ public void DecodesLiteralHeaderFieldWithoutIndexing_NewName_HuffmanEncodedValue
265319
TestDecodeWithoutIndexing(encoded, _headerNameString, _headerValueString);
266320
}
267321

322+
[Fact]
323+
public void DecodesLiteralHeaderFieldWithoutIndexing_NewName_HuffmanEncodedValue_Empty()
324+
{
325+
byte[] encoded = _literalHeaderFieldWithoutIndexingNewName
326+
.Concat(_headerName)
327+
.Concat(_literalEmptyStringHuffman)
328+
.ToArray();
329+
330+
TestDecodeWithoutIndexing(encoded, _headerNameString, string.Empty);
331+
}
332+
268333
[Fact]
269334
public void DecodesLiteralHeaderFieldWithoutIndexing_NewName_HuffmanEncodedNameAndValue()
270335
{
@@ -276,6 +341,19 @@ public void DecodesLiteralHeaderFieldWithoutIndexing_NewName_HuffmanEncodedNameA
276341
TestDecodeWithoutIndexing(encoded, _headerNameString, _headerValueString);
277342
}
278343

344+
[Fact]
345+
public void DecodesLiteralHeaderFieldWithoutIndexing_NewName_HuffmanEncodedNameAndValue_Empty()
346+
{
347+
byte[] encoded = _literalHeaderFieldWithoutIndexingNewName
348+
.Concat(_literalEmptyStringHuffman)
349+
.Concat(_literalEmptyStringHuffman)
350+
.ToArray();
351+
352+
HPackDecodingException exception = Assert.Throws<HPackDecodingException>(() => _decoder.Decode(encoded, endHeaders: true, handler: _handler));
353+
Assert.Equal(SR.Format(SR.net_http_invalid_header_name, string.Empty), exception.Message);
354+
Assert.Empty(_handler.DecodedHeaders);
355+
}
356+
279357
[Fact]
280358
public void DecodesLiteralHeaderFieldWithoutIndexing_IndexedName()
281359
{

0 commit comments

Comments
 (0)