Skip to content

Commit

Permalink
Merge pull request #2107 from Shopify/dnwe/skip-tagged-fields
Browse files Browse the repository at this point in the history
fix: skip over KIP-482 tagged fields
  • Loading branch information
dnwe committed Jan 12, 2022
2 parents 923b70f + 31a5366 commit 9d82f86
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion api_versions_response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
0x00, 0x01,
0x00, // tagged fields
0x00, 0x00, 0x00, 0x00, // throttle time
0x00, // tagged fields
0x01, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // tagged fields (empty SupportedFeatures)
}
)

Expand Down
4 changes: 3 additions & 1 deletion encoder_decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ func versionedDecode(buf []byte, in versionedDecoder, version int16) error {
}

if helper.off != len(buf) {
return PacketDecodingError{"invalid length"}
return PacketDecodingError{
Info: fmt.Sprintf("invalid length (off=%d, len=%d)", helper.off, len(buf)),
}
}

return nil
Expand Down
30 changes: 21 additions & 9 deletions real_decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import (
)

var (
errInvalidArrayLength = PacketDecodingError{"invalid array length"}
errInvalidByteSliceLength = PacketDecodingError{"invalid byteslice length"}
errInvalidStringLength = PacketDecodingError{"invalid string length"}
errVarintOverflow = PacketDecodingError{"varint overflow"}
errUVarintOverflow = PacketDecodingError{"uvarint overflow"}
errInvalidBool = PacketDecodingError{"invalid bool"}
errUnsupportedTaggedFields = PacketDecodingError{"non-empty tagged fields are not supported yet"}
errInvalidArrayLength = PacketDecodingError{"invalid array length"}
errInvalidByteSliceLength = PacketDecodingError{"invalid byteslice length"}
errInvalidStringLength = PacketDecodingError{"invalid string length"}
errVarintOverflow = PacketDecodingError{"varint overflow"}
errUVarintOverflow = PacketDecodingError{"uvarint overflow"}
errInvalidBool = PacketDecodingError{"invalid bool"}
)

type realDecoder struct {
Expand Down Expand Up @@ -149,8 +148,21 @@ func (rd *realDecoder) getEmptyTaggedFieldArray() (int, error) {
return 0, err
}

if tagCount != 0 {
return 0, errUnsupportedTaggedFields
// skip over any tagged fields without deserializing them
// as we don't currently support doing anything with them
for i := uint64(0); i < tagCount; i++ {
// fetch and ignore tag identifier
_, err := rd.getUVarint()
if err != nil {
return 0, err
}
length, err := rd.getUVarint()
if err != nil {
return 0, err
}
if _, err := rd.getRawBytes(int(length)); err != nil {
return 0, err
}
}

return 0, nil
Expand Down

0 comments on commit 9d82f86

Please sign in to comment.