From d06cdc3840c943e1130d85effe8b4376bf703ed4 Mon Sep 17 00:00:00 2001 From: SailorStu Date: Tue, 17 Oct 2023 07:56:56 -0700 Subject: [PATCH] Resolve Panic from a Received payload with message size field value less than 8 byte header size. --- uacp/conn.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/uacp/conn.go b/uacp/conn.go index a9eda06a..c2acb79c 100644 --- a/uacp/conn.go +++ b/uacp/conn.go @@ -367,7 +367,10 @@ func (c *Conn) Receive() ([]byte, error) { } if h.MessageSize > c.ack.ReceiveBufSize { - return nil, errors.Errorf("uacp: message too large: %d > %d bytes", h.MessageSize, c.ack.ReceiveBufSize) + return nil, errors.Errorf("uacp: message too large: %d > %d bytes. MsgType=%s, ChunkType=%c", h.MessageSize, c.ack.ReceiveBufSize, h.MessageType, h.ChunkType) + } + if h.MessageSize < hdrlen { + return nil, errors.Errorf("uacp: message too small: %d bytes. MsgType=%s, ChunkType=%c.", h.MessageSize, h.MessageType, h.ChunkType) } if _, err := io.ReadFull(c, b[hdrlen:h.MessageSize]); err != nil {