fix(protocol): limit size of incoming request messages (#10629)
Signed-off-by: Jakob Borg <jakob@kastelo.net>
This commit is contained in:
@@ -49,6 +49,10 @@ const (
|
||||
// MaxBlockSize is the maximum block size allowed
|
||||
MaxBlockSize = 16 << MiB
|
||||
|
||||
// MaxRequestSize is the largest amount of data that can be read in a
|
||||
// single request
|
||||
MaxRequestSize = 2 * MaxBlockSize
|
||||
|
||||
// DesiredPerFileBlocks is the number of blocks we aim for per file
|
||||
DesiredPerFileBlocks = 2000
|
||||
|
||||
@@ -457,14 +461,6 @@ func (c *rawConnection) dispatcherLoop() (err error) {
|
||||
}
|
||||
}
|
||||
|
||||
switch msg := msg.(type) {
|
||||
case *bep.Request:
|
||||
err = checkFilename(msg.Name)
|
||||
}
|
||||
if err != nil {
|
||||
return newProtocolError(err, msgContext)
|
||||
}
|
||||
|
||||
switch msg := msg.(type) {
|
||||
case *bep.ClusterConfig:
|
||||
err = c.model.ClusterConfig(clusterConfigFromWire(msg))
|
||||
@@ -484,6 +480,15 @@ func (c *rawConnection) dispatcherLoop() (err error) {
|
||||
err = c.handleIndexUpdate(idxUp)
|
||||
|
||||
case *bep.Request:
|
||||
if err := checkFilename(msg.Name); err != nil {
|
||||
return newProtocolError(err, msgContext)
|
||||
}
|
||||
if msg.Size <= 0 {
|
||||
return newProtocolError(fmt.Errorf("request size %d too small", msg.Size), msgContext)
|
||||
}
|
||||
if msg.Size > MaxRequestSize {
|
||||
return newProtocolError(fmt.Errorf("request size %d exceeds maximum allowed", msg.Size), msgContext)
|
||||
}
|
||||
go c.handleRequest(requestFromWire(msg))
|
||||
|
||||
case *bep.Response:
|
||||
|
||||
Reference in New Issue
Block a user