Skip to content

Commit 8d33435

Browse files
authored
Guard against empty inputs list in unify() (#1668)
This can panic if called incorrectly, return an empty list instead. Signed-off-by: Jon Johnson <[email protected]>
1 parent e8cf036 commit 8d33435

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

pkg/build/lock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ type resolved struct {
146146

147147
// unify returns (locked packages (per arch), missing packages (per arch), error)
148148
func unify(originals []string, inputs []resolved) (map[string][]string, map[string][]string, error) {
149-
if len(originals) == 0 {
149+
if len(originals) == 0 || len(inputs) == 0 {
150150
// If there are no original packages, then we can't really do anything.
151151
// This used to return nil but multi-arch unification assumes we always
152152
// have an "index" entry, even if it's empty, so we return this now.

pkg/build/lock_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ func TestUnify(t *testing.T) {
3333
}{{
3434
name: "empty",
3535
want: map[string][]string{"index": {}},
36+
}, {
37+
name: "no inputs",
38+
originals: []string{"foo", "bar", "baz"},
39+
want: map[string][]string{"index": {}},
3640
}, {
3741
name: "simple single arch",
3842
originals: []string{"foo", "bar", "baz"},

0 commit comments

Comments
 (0)