From 09a37c55a544f313e49b70ac1523cc01f2e00c72 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Wed, 4 Sep 2024 10:57:28 +0800 Subject: [PATCH 1/2] remove N=1 check when decoding a literal field line with name reference This field is only used to determine if the dynamic table can be used when this field is re-encoded. Since we currently don't support use of the dynamic table, the N value is irrelevant. --- decoder.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/decoder.go b/decoder.go index c900194..40bc79e 100644 --- a/decoder.go +++ b/decoder.go @@ -196,7 +196,7 @@ func (d *Decoder) parseIndexedHeaderField() error { func (d *Decoder) parseLiteralHeaderField() error { buf := d.buf - if buf[0]&0x20 > 0 || buf[0]&0x10 == 0 { + if buf[0]&0x10 == 0 { return errNoDynamicTable } index, buf, err := readVarInt(4, buf) From b6dae4c1bab68f35ccc83f3038c20fa870e3e9b3 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Wed, 4 Sep 2024 13:57:17 +0800 Subject: [PATCH 2/2] add comment and test --- decoder.go | 4 ++++ decoder_test.go | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/decoder.go b/decoder.go index 40bc79e..88ea8eb 100644 --- a/decoder.go +++ b/decoder.go @@ -199,6 +199,10 @@ func (d *Decoder) parseLiteralHeaderField() error { if buf[0]&0x10 == 0 { return errNoDynamicTable } + // We don't need to check the value of the N-bit here. + // It's only relevant when re-encoding header fields, + // and determines whether the header field can be added to the dynamic table. + // Since we don't support the dynamic table, we can ignore it. index, buf, err := readVarInt(4, buf) if err != nil { return err diff --git a/decoder_test.go b/decoder_test.go index ec75962..0a06cda 100644 --- a/decoder_test.go +++ b/decoder_test.go @@ -119,9 +119,21 @@ func TestDecoderInvalidIndexedHeaderFields(t *testing.T) { } func TestDecoderLiteralHeaderFieldWithNameReference(t *testing.T) { + t.Run("without the N-bit", func(t *testing.T) { + testDecoderLiteralHeaderFieldWithNameReference(t, false) + }) + t.Run("with the N-bit", func(t *testing.T) { + testDecoderLiteralHeaderFieldWithNameReference(t, true) + }) +} + +func testDecoderLiteralHeaderFieldWithNameReference(t *testing.T, n bool) { decoder := newRecordingDecoder() data := appendVarInt(nil, 4, 49) data[0] ^= 0x40 | 0x10 + if n { + data[0] |= 0x20 + } data = appendVarInt(data, 7, 6) data = append(data, []byte("foobar")...) doPartialWrites(t, decoder, insertPrefix(data))