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.
func (p *QuicProxy) runProxy() error {
for {
buffer := make([]byte, protocol.MaxPacketSize)
buffer := make([]byte, protocol.MaxReceivePacketSize)
n, cliaddr, err := p.conn.ReadFromUDP(buffer)
if err != nil {
return err
@@ -211,7 +211,7 @@ func (p *QuicProxy) runProxy() error {
// runConnection handles packets from server to a single client
func (p *QuicProxy) runConnection(conn *connection) error {
for {
buffer := make([]byte, protocol.MaxPacketSize)
buffer := make([]byte, protocol.MaxReceivePacketSize)
n, err := conn.ServerConn.Read(buffer)
if err != nil {
return err

View File

@@ -2,9 +2,9 @@ package protocol
import "time"
// MaxPacketSize is the maximum packet size, including the public header, 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)
const MaxPacketSize ByteCount = 1350
// MaxPacketSize is the maximum packet size that we use for sending packets.
// It includes the QUIC packet header, but excludes the UDP and IP header.
const MaxPacketSize ByteCount = 1200
// 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

View File

@@ -61,8 +61,11 @@ func ParseStreamFrame(r *bytes.Reader, version protocol.VersionNumber) (*StreamF
}
}
if dataLen > uint16(protocol.MaxPacketSize) {
return nil, qerr.Error(qerr.InvalidStreamData, "data len too large")
// shortcut to prevent the unneccessary allocation of dataLen bytes
// 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 {
@@ -72,6 +75,7 @@ func ParseStreamFrame(r *bytes.Reader, version protocol.VersionNumber) (*StreamF
if dataLen != 0 {
frame.Data = make([]byte, dataLen)
if _, err := io.ReadFull(r, frame.Data); err != nil {
// this should never happen, since we already checked the dataLen earlier
return nil, err
}
}

View File

@@ -2,6 +2,7 @@ package wire
import (
"bytes"
"io"
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/qerr"
@@ -168,9 +169,9 @@ var _ = Describe("StreamFrame", 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)
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() {