瀏覽代碼

http2: dynamic table updates must occur first

Dynamic table size updates must occur at the beginning of the first
header block.

Updates golang/go#25023

Change-Id: I7fd4f191da0a97cab26666545191460a6f6c1433
Reviewed-on: https://go-review.googlesource.com/111681
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Michael Fraenkel 7 年之前
父節點
當前提交
d11bb6cd8e
共有 2 個文件被更改,包括 25 次插入0 次删除
  1. 6 0
      http2/hpack/hpack.go
  2. 19 0
      http2/hpack/hpack_test.go

+ 6 - 0
http2/hpack/hpack.go

@@ -389,6 +389,12 @@ func (d *Decoder) callEmit(hf HeaderField) error {
 
 // (same invariants and behavior as parseHeaderFieldRepr)
 func (d *Decoder) parseDynamicTableSizeUpdate() error {
+	// RFC 7541, sec 4.2: This dynamic table size update MUST occur at the
+	// beginning of the first header block following the change to the dynamic table size.
+	if d.dynTab.size > 0 {
+		return DecodingError{errors.New("dynamic table size update MUST occur at the beginning of a header block")}
+	}
+
 	buf := d.buf
 	size, buf, err := readVarInt(5, buf)
 	if err != nil {

+ 19 - 0
http2/hpack/hpack_test.go

@@ -720,3 +720,22 @@ func TestSaveBufLimit(t *testing.T) {
 		t.Fatalf("Write error = %v; want ErrStringLength", err)
 	}
 }
+
+func TestDynamicSizeUpdate(t *testing.T) {
+	var buf bytes.Buffer
+	enc := NewEncoder(&buf)
+	enc.SetMaxDynamicTableSize(255)
+	enc.WriteField(HeaderField{Name: "foo", Value: "bar"})
+
+	d := NewDecoder(4096, nil)
+	_, err := d.DecodeFull(buf.Bytes())
+	if err != nil {
+		t.Fatalf("unexpected error: got = %v", err)
+	}
+
+	// must fail since the dynamic table update must be at the beginning
+	_, err = d.DecodeFull(buf.Bytes())
+	if err == nil {
+		t.Fatalf("dynamic table size update not at the beginning of a header block")
+	}
+}