diff --git a/client.go b/client.go index f32ef49e..3c307998 100644 --- a/client.go +++ b/client.go @@ -116,7 +116,8 @@ func (c *client) listen() { var addr net.Addr data := getPacketBuffer() data = data[:protocol.MaxReceivePacketSize] - + // The packet size should not exceed protocol.MaxReceivePacketSize bytes + // If it does, we only read a truncated packet, which will then end up undecryptable n, addr, err = c.conn.Read(data) if err != nil { if !strings.HasSuffix(err.Error(), "use of closed network connection") { @@ -141,14 +142,9 @@ func (c *client) listen() { } func (c *client) handlePacket(remoteAddr net.Addr, packet []byte) error { - if protocol.ByteCount(len(packet)) > protocol.MaxReceivePacketSize { - return qerr.PacketTooLarge - } - rcvTime := time.Now() r := bytes.NewReader(packet) - hdr, err := ParsePublicHeader(r, protocol.PerspectiveServer) if err != nil { return qerr.Error(qerr.InvalidPacketHeader, err.Error()) diff --git a/client_test.go b/client_test.go index bdef8b31..8df1e3d3 100644 --- a/client_test.go +++ b/client_test.go @@ -146,11 +146,6 @@ var _ = Describe("Client", func() { }) Context("handling packets", func() { - It("errors on too large packets", func() { - err := cl.handlePacket(nil, bytes.Repeat([]byte{'f'}, int(protocol.MaxReceivePacketSize+1))) - Expect(err).To(MatchError(qerr.PacketTooLarge)) - }) - It("handles packets", func() { ph := PublicHeader{ PacketNumber: 1, diff --git a/server.go b/server.go index f003bef8..7ddb018b 100644 --- a/server.go +++ b/server.go @@ -84,6 +84,8 @@ func (s *server) Serve() error { for { data := getPacketBuffer() data = data[:protocol.MaxReceivePacketSize] + // The packet size should not exceed protocol.MaxReceivePacketSize bytes + // If it does, we only read a truncated packet, which will then end up undecryptable n, remoteAddr, err := s.conn.ReadFrom(data) if err != nil { if strings.HasSuffix(err.Error(), "use of closed network connection") { @@ -122,14 +124,9 @@ func (s *server) Addr() net.Addr { } func (s *server) handlePacket(pconn net.PacketConn, remoteAddr net.Addr, packet []byte) error { - if protocol.ByteCount(len(packet)) > protocol.MaxReceivePacketSize { - return qerr.PacketTooLarge - } - rcvTime := time.Now() r := bytes.NewReader(packet) - hdr, err := ParsePublicHeader(r, protocol.PerspectiveClient) if err != nil { return qerr.Error(qerr.InvalidPacketHeader, err.Error()) diff --git a/server_test.go b/server_test.go index 6cc68f1e..25a0f8f5 100644 --- a/server_test.go +++ b/server_test.go @@ -255,11 +255,6 @@ var _ = Describe("Server", func() { Expect(err.(*qerr.QuicError).ErrorCode).To(Equal(qerr.InvalidPacketHeader)) }) - It("errors on large packets", func() { - err := serv.handlePacket(nil, nil, bytes.Repeat([]byte{'a'}, int(protocol.MaxReceivePacketSize)+1)) - Expect(err).To(MatchError(qerr.PacketTooLarge)) - }) - It("ignores public resets for unknown connections", func() { err := serv.handlePacket(nil, nil, writePublicReset(999, 1, 1337)) Expect(err).ToNot(HaveOccurred())