From 623cc4e2aaa2d67d196cb972bd525a60544d2148 Mon Sep 17 00:00:00 2001 From: Sidhant Kohli Date: Fri, 15 Nov 2024 15:09:45 -0800 Subject: [PATCH] fix: update key len (#2223) Signed-off-by: Sidhant Kohli --- pkg/isb/serde.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/isb/serde.go b/pkg/isb/serde.go index d62b168fea..f29846999b 100644 --- a/pkg/isb/serde.go +++ b/pkg/isb/serde.go @@ -61,7 +61,7 @@ type headerPreamble struct { // message ID len IDLen int16 // message keys length - KeysLen int16 + KeysLen int32 // header length HeadersLen int16 } @@ -77,7 +77,7 @@ func (h Header) MarshalBinary() (data []byte, err error) { MLen: int32(len(msgInfo)), MsgKind: h.Kind, IDLen: int16(len(h.ID)), - KeysLen: int16(len(h.Keys)), + KeysLen: int32(len(h.Keys)), HeadersLen: int16(len(h.Headers)), } if err = binary.Write(buf, binary.LittleEndian, preamble); err != nil { @@ -93,7 +93,7 @@ func (h Header) MarshalBinary() (data []byte, err error) { return nil, err } for i := 0; i < len(h.Keys); i++ { - if err = binary.Write(buf, binary.LittleEndian, int16(len(h.Keys[i]))); err != nil { + if err = binary.Write(buf, binary.LittleEndian, int32(len(h.Keys[i]))); err != nil { return nil, err } if err = binary.Write(buf, binary.LittleEndian, []byte(h.Keys[i])); err != nil { @@ -141,11 +141,14 @@ func (h *Header) UnmarshalBinary(data []byte) (err error) { return err } keys := make([]string, 0) - for i := int16(0); i < preamble.KeysLen; i++ { - var kl int16 + for i := int32(0); i < preamble.KeysLen; i++ { + var kl int32 if err = binary.Read(r, binary.LittleEndian, &kl); err != nil { return err } + if kl < 0 { + return fmt.Errorf("invalid key len in header") + } var k = make([]byte, kl) if err = binary.Read(r, binary.LittleEndian, k); err != nil { return err