network: don't allocate memory for messages larger than PayloadMaxSize

This commit is contained in:
Roman Khimov 2020-06-18 11:31:19 +03:00
parent 39fd799992
commit 8388e509df

View file

@ -103,14 +103,14 @@ func (m *Message) Decode(br *io.BinReader) error {
m.Payload = payload.NewNullPayload()
return nil
}
if l > PayloadMaxSize {
return errors.New("invalid payload size")
}
m.compressedPayload = make([]byte, l)
br.ReadBytes(m.compressedPayload)
if br.Err != nil {
return br.Err
}
if len(m.compressedPayload) > PayloadMaxSize {
return errors.New("invalid payload size")
}
return m.decodePayload()
}