Skip to content

Commit

Permalink
Don't panic when decoding empty slice. (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
winder authored Dec 19, 2024
1 parent 67e180e commit f9157a7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/types/ccipocr3/plugin_execute_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func (eri ExecuteReportInfo) Encode() ([]byte, error) {
// DecodeExecuteReportInfo is a version aware decode function for the execute
// report info bytes.
func DecodeExecuteReportInfo(data []byte) (ExecuteReportInfo, error) {
if len(data) == 0 {
return ExecuteReportInfo{}, nil
}

switch data[0] {
case 1:
var result ExecuteReportInfo
Expand Down
7 changes: 7 additions & 0 deletions pkg/types/ccipocr3/plugin_execute_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ func TestDecodeExecuteReportInfo(t *testing.T) {
_, err := DecodeExecuteReportInfo(data)
require.ErrorContains(t, err, "object") // not super helpful...
}

// empty
{
ri, err := DecodeExecuteReportInfo(nil)
require.NoError(t, err)
require.Equal(t, ExecuteReportInfo{}, ri)
}
}

func TestExecuteReportInfo_EncodeDecode(t *testing.T) {
Expand Down

0 comments on commit f9157a7

Please sign in to comment.