Skip to content

Commit 6020532

Browse files
Fix panic for DSSE canonicalization (#1923)
Handles if the array of signatures contains missing data. Signed-off-by: Hayden Blauzvern <[email protected]>
1 parent 0793130 commit 6020532

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

pkg/types/dsse/v0.0.1/entry.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,12 @@ func (v *V001Entry) Canonicalize(_ context.Context) ([]byte, error) {
276276
ProposedContent: nil, // this is explicitly done as we don't want to canonicalize the envelope
277277
}
278278

279+
for _, s := range canonicalEntry.Signatures {
280+
if s.Signature == nil {
281+
return nil, errors.New("canonical entry missing required signature")
282+
}
283+
}
284+
279285
sort.Slice(canonicalEntry.Signatures, func(i, j int) bool {
280286
return *canonicalEntry.Signatures[i].Signature < *canonicalEntry.Signatures[j].Signature
281287
})

pkg/types/dsse/v0.0.1/entry_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,3 +529,12 @@ func TestInsertable(t *testing.T) {
529529
})
530530
}
531531
}
532+
533+
func TestCanonicalizeHandlesInvalidInput(t *testing.T) {
534+
v := &V001Entry{}
535+
v.DSSEObj.Signatures = []*models.DSSEV001SchemaSignaturesItems0{{Signature: nil}, {Signature: nil}}
536+
_, err := v.Canonicalize(context.TODO())
537+
if err == nil {
538+
t.Fatalf("expected error canonicalizing invalid input")
539+
}
540+
}

0 commit comments

Comments
 (0)