Merge pull request #883 from lucas-clemente/fix-882

reduce the maximum packet size of sent packets to 1200 bytes
This commit is contained in:
Marten Seemann
2017-10-20 05:23:14 -05:00
committed by GitHub
4 changed files with 14 additions and 9 deletions

View File

@@ -164,7 +164,7 @@ func (p *QuicProxy) newConnection(cliAddr *net.UDPAddr) (*connection, error) {
// runProxy listens on the proxy address and handles incoming packets. // runProxy listens on the proxy address and handles incoming packets.
func (p *QuicProxy) runProxy() error { func (p *QuicProxy) runProxy() error {
for { for {
buffer := make([]byte, protocol.MaxPacketSize) buffer := make([]byte, protocol.MaxReceivePacketSize)
n, cliaddr, err := p.conn.ReadFromUDP(buffer) n, cliaddr, err := p.conn.ReadFromUDP(buffer)
if err != nil { if err != nil {
return err return err
@@ -211,7 +211,7 @@ func (p *QuicProxy) runProxy() error {
// runConnection handles packets from server to a single client // runConnection handles packets from server to a single client
func (p *QuicProxy) runConnection(conn *connection) error { func (p *QuicProxy) runConnection(conn *connection) error {
for { for {
buffer := make([]byte, protocol.MaxPacketSize) buffer := make([]byte, protocol.MaxReceivePacketSize)
n, err := conn.ServerConn.Read(buffer) n, err := conn.ServerConn.Read(buffer)
if err != nil { if err != nil {
return err return err

View File

@@ -2,9 +2,9 @@ package protocol
import "time" import "time"
// MaxPacketSize is the maximum packet size, including the public header, that we use for sending packets // MaxPacketSize is the maximum packet size that we use for sending packets.
// This is the value used by Chromium for a QUIC packet sent using IPv6 (for IPv4 it would be 1370) // It includes the QUIC packet header, but excludes the UDP and IP header.
const MaxPacketSize ByteCount = 1350 const MaxPacketSize ByteCount = 1200
// NonForwardSecurePacketSizeReduction is the number of bytes a non forward-secure packet has to be smaller than a forward-secure packet // NonForwardSecurePacketSizeReduction is the number of bytes a non forward-secure packet has to be smaller than a forward-secure packet
// This makes sure that those packets can always be retransmitted without splitting the contained StreamFrames // This makes sure that those packets can always be retransmitted without splitting the contained StreamFrames

View File

@@ -61,8 +61,11 @@ func ParseStreamFrame(r *bytes.Reader, version protocol.VersionNumber) (*StreamF
} }
} }
if dataLen > uint16(protocol.MaxPacketSize) { // shortcut to prevent the unneccessary allocation of dataLen bytes
return nil, qerr.Error(qerr.InvalidStreamData, "data len too large") // if the dataLen is larger than the remaining length of the packet
// reading the packet contents would result in EOF when attempting to READ
if int(dataLen) > r.Len() {
return nil, io.EOF
} }
if !frame.DataLenPresent { if !frame.DataLenPresent {
@@ -72,6 +75,7 @@ func ParseStreamFrame(r *bytes.Reader, version protocol.VersionNumber) (*StreamF
if dataLen != 0 { if dataLen != 0 {
frame.Data = make([]byte, dataLen) frame.Data = make([]byte, dataLen)
if _, err := io.ReadFull(r, frame.Data); err != nil { if _, err := io.ReadFull(r, frame.Data); err != nil {
// this should never happen, since we already checked the dataLen earlier
return nil, err return nil, err
} }
} }

View File

@@ -2,6 +2,7 @@ package wire
import ( import (
"bytes" "bytes"
"io"
"github.com/lucas-clemente/quic-go/internal/protocol" "github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/qerr" "github.com/lucas-clemente/quic-go/qerr"
@@ -168,9 +169,9 @@ var _ = Describe("StreamFrame", func() {
}) })
It("rejects frames to too large dataLen", func() { It("rejects frames to too large dataLen", func() {
b := bytes.NewReader([]byte{0xa0, 0x1, 0xff, 0xf}) b := bytes.NewReader([]byte{0xa0, 0x1, 0xff, 0xff})
_, err := ParseStreamFrame(b, protocol.VersionWhatever) _, err := ParseStreamFrame(b, protocol.VersionWhatever)
Expect(err).To(MatchError(qerr.Error(qerr.InvalidStreamData, "data len too large"))) Expect(err).To(MatchError(io.EOF))
}) })
It("rejects frames that overflow the offset", func() { It("rejects frames that overflow the offset", func() {