From 5cb2e8265cd2832b0d9b961ca48645c1ebd993b3 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Fri, 27 May 2022 17:35:00 +0200 Subject: [PATCH] fix handling of unknown frames in the stream hijacker --- http3/frames.go | 3 +-- http3/frames_test.go | 5 +---- http3/roundtrip.go | 2 +- http3/server.go | 2 +- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/http3/frames.go b/http3/frames.go index 5fb4f082eba..1a992bf8a7b 100644 --- a/http3/frames.go +++ b/http3/frames.go @@ -33,11 +33,10 @@ func parseNextFrame(r io.Reader, unknownFrameHandler unknownFrameHandlerFunc) (f if err != nil { return nil, err } - // If the unknownFrameHandler didn't process the frame, it is our responsibility to skip it. if hijacked { return nil, errHijacked } - continue + // If the unknownFrameHandler didn't process the frame, it is our responsibility to skip it. } l, err := quicvarint.Read(qr) if err != nil { diff --git a/http3/frames_test.go b/http3/frames_test.go index 40ca3c124a4..0d14f35df4a 100644 --- a/http3/frames_test.go +++ b/http3/frames_test.go @@ -206,6 +206,7 @@ var _ = Describe("Frames", func() { buf := &bytes.Buffer{} quicvarint.Write(buf, 1337) customFrameContents := []byte("custom frame") + quicvarint.Write(buf, uint64(len(customFrameContents))) buf.Write(customFrameContents) (&dataFrame{Length: 6}).Write(buf) buf.WriteString("foobar") @@ -214,10 +215,6 @@ var _ = Describe("Frames", func() { frame, err := parseNextFrame(buf, func(ft FrameType) (hijacked bool, err error) { Expect(ft).To(BeEquivalentTo(1337)) called = true - b := make([]byte, len(customFrameContents)) - _, err = io.ReadFull(buf, b) - Expect(err).ToNot(HaveOccurred()) - Expect(string(b)).To(Equal(string(customFrameContents))) return false, nil }) Expect(err).ToNot(HaveOccurred()) diff --git a/http3/roundtrip.go b/http3/roundtrip.go index f5fe2ab9451..4dd1e4a84a2 100644 --- a/http3/roundtrip.go +++ b/http3/roundtrip.go @@ -53,7 +53,7 @@ type RoundTripper struct { // When set, this callback is called for the first unknown frame parsed on a bidirectional stream. // It is called right after parsing the frame type. - // Callers can either process the frame and return control of the stream back to HTTP/3 + // Callers can either ignore the frame and return control of the stream back to HTTP/3 // (by returning hijacked false). // Alternatively, callers can take over the QUIC stream (by returning hijacked true). StreamHijacker func(FrameType, quic.Connection, quic.Stream) (hijacked bool, err error) diff --git a/http3/server.go b/http3/server.go index 645b2b3ea27..1ed7c7aad7f 100644 --- a/http3/server.go +++ b/http3/server.go @@ -178,7 +178,7 @@ type Server struct { // StreamHijacker, when set, is called for the first unknown frame parsed on a bidirectional stream. // It is called right after parsing the frame type. - // Callers can either process the frame and return control of the stream back to HTTP/3 + // Callers can either ignore the frame and return control of the stream back to HTTP/3 // (by returning hijacked false). // Alternatively, callers can take over the QUIC stream (by returning hijacked true). StreamHijacker func(FrameType, quic.Connection, quic.Stream) (hijacked bool, err error)