Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SR: prevent panic when no decode function is registered #745

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/sr/serde.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ func (s *Serde) decodeFind(b []byte) ([]byte, tserde, error) {
t = t.subindex[idx]
}
}
if !t.exists {
if !t.exists || t.decode == nil {
return nil, tserde{}, ErrNotRegistered
}
return b, t, nil
Expand Down
5 changes: 3 additions & 2 deletions pkg/sr/serde_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func TestSerde(t *testing.T) {
serde.Register(3, idx4{}, Index(0, 0, 1))
serde.Register(3, idx3{}, Index(0, 0))
serde.Register(5, oneidx{}, Index(0), GenerateFn(func() any { return &oneidx{Foo: "defoo", Bar: "debar"} }))
serde.Register(101, struct{}{}, DecodeFn(nil))

for i, test := range []struct {
enc any
Expand Down Expand Up @@ -154,8 +155,8 @@ func TestSerde(t *testing.T) {
if _, err := serde.DecodeNew([]byte{0, 0, 0, 0, 99}); err != ErrNotRegistered {
t.Errorf("got %v != exp ErrNotRegistered", err)
}
if _, err := serde.DecodeNew([]byte{0, 0, 0, 0, 100, 0}); err != ErrNotRegistered {
// schema is registered but type is unknown
if _, err := serde.DecodeNew([]byte{0, 0, 0, 0, 101, 0}); err != ErrNotRegistered {
// schema is registered but no decode function
t.Errorf("got %v != exp ErrNotRegistered", err)
}
}
Expand Down