Skip to content

Commit

Permalink
Merge pull request #835 from mreiferson/max-messages
Browse files Browse the repository at this point in the history
nsqd: bound MPUB messages to derived limit
  • Loading branch information
mreiferson authored Dec 28, 2016
2 parents 15cc418 + da2e4bd commit 866aa08
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion nsqd/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func (s *httpServer) doMPUB(w http.ResponseWriter, req *http.Request, ps httprou
if ok {
tmp := make([]byte, 4)
msgs, err = readMPUB(req.Body, tmp, s.ctx.nsqd.idChan,
s.ctx.nsqd.getOpts().MaxMsgSize)
s.ctx.nsqd.getOpts().MaxMsgSize, s.ctx.nsqd.getOpts().MaxBodySize)
if err != nil {
return nil, http_api.Err{413, err.(*protocol.FatalClientErr).Code[2:]}
}
Expand Down
8 changes: 5 additions & 3 deletions nsqd/protocol_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ func (p *protocolV2) MPUB(client *clientV2, params [][]byte) ([]byte, error) {
}

messages, err := readMPUB(client.Reader, client.lenSlice, p.ctx.nsqd.idChan,
p.ctx.nsqd.getOpts().MaxMsgSize)
p.ctx.nsqd.getOpts().MaxMsgSize, p.ctx.nsqd.getOpts().MaxBodySize)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -930,13 +930,15 @@ func (p *protocolV2) TOUCH(client *clientV2, params [][]byte) ([]byte, error) {
return nil, nil
}

func readMPUB(r io.Reader, tmp []byte, idChan chan MessageID, maxMessageSize int64) ([]*Message, error) {
func readMPUB(r io.Reader, tmp []byte, idChan chan MessageID, maxMessageSize int64, maxBodySize int64) ([]*Message, error) {
numMessages, err := readLen(r, tmp)
if err != nil {
return nil, protocol.NewFatalClientErr(err, "E_BAD_BODY", "MPUB failed to read message count")
}

if numMessages <= 0 {
// 4 == total num, 5 == length + min 1
maxMessages := (maxBodySize - 4) / 5
if numMessages <= 0 || int64(numMessages) > maxMessages {
return nil, protocol.NewFatalClientErr(err, "E_BAD_BODY",
fmt.Sprintf("MPUB invalid message count %d", numMessages))
}
Expand Down

0 comments on commit 866aa08

Please sign in to comment.