Skip to content

Commit

Permalink
Trigger an unmarshal panic
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Nov 30, 2023
1 parent 0f55583 commit d566ee3
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions types/serde_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"testing"
"time"
"unsafe"

coroutinev1 "github.com/stealthrocket/coroutine/gen/proto/go/coroutine/v1"
)

func TestSerdeTime(t *testing.T) {
Expand Down Expand Up @@ -936,3 +938,31 @@ func BenchmarkRoundtripString(b *testing.B) {
}
}
}

func TestUnmarshalInvalid(t *testing.T) {
for _, invalid := range [][]byte{
[]byte("foobar"),
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
mustSerialize(&coroutinev1.State{
Build: buildInfo,
Root: &coroutinev1.Region{
Type: 0,
Data: []byte{1, 0},
},
}),
} {
t.Run(fmt.Sprintf("%v", invalid), func(t *testing.T) {
if _, err := Deserialize(invalid); err == nil {
t.Error("expected error, got nil")
}
})
}
}

func mustSerialize(s *coroutinev1.State) []byte {
b, err := s.MarshalVT()
if err != nil {
panic(err)
}
return b
}

0 comments on commit d566ee3

Please sign in to comment.