Skip to content

Commit

Permalink
Merge pull request #131 from berty/fix/read-max-size
Browse files Browse the repository at this point in the history
  • Loading branch information
gfanton authored Apr 6, 2023
2 parents abc7b33 + 62a3ff0 commit 1c130c4
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pubsub/directchannel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

const PROTOCOL = "/go-orbit-db/direct-channel/1.2.0"
const DelimitedReadMaxSize = 2048
const DelimitedReadMaxSize = 1024 * 1024 * 4 // mb

type directChannel struct {
logger *zap.Logger
Expand Down Expand Up @@ -57,8 +57,9 @@ func (d *directChannel) handleNewPeer(s network.Stream) {
}

length := int(length64)
if length < 0 || length > DelimitedReadMaxSize {
d.logger.Error("invalid buffer length", zap.Error(io.ErrShortBuffer))

if length > DelimitedReadMaxSize {
d.logger.Error(fmt.Sprintf("received data exceeding maximum allowed size (%d > %d)", length, DelimitedReadMaxSize))
return
}

Expand Down

0 comments on commit 1c130c4

Please sign in to comment.