From 8388e509df2cd1c643b5254a22ec7f47bed2cea0 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Thu, 18 Jun 2020 11:31:19 +0300 Subject: [PATCH] network: don't allocate memory for messages larger than PayloadMaxSize --- pkg/network/message.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/network/message.go b/pkg/network/message.go index b77e1054f..98bd89320 100644 --- a/pkg/network/message.go +++ b/pkg/network/message.go @@ -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() }