Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove N=1 check when decoding a literal field line with name reference #52

Merged
merged 2 commits into from
Sep 4, 2024
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
6 changes: 5 additions & 1 deletion decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,13 @@ 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
}
// 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
Expand Down
12 changes: 12 additions & 0 deletions decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down