Skip to content

Commit

Permalink
fix: update key len (#2223)
Browse files Browse the repository at this point in the history
Signed-off-by: Sidhant Kohli <[email protected]>
  • Loading branch information
kohlisid authored Nov 15, 2024
1 parent 89ea33f commit 623cc4e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pkg/isb/serde.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type headerPreamble struct {
// message ID len
IDLen int16
// message keys length
KeysLen int16
KeysLen int32
// header length
HeadersLen int16
}
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 623cc4e

Please sign in to comment.