From c2bfa4120d4809ff70ed3e301b6614a9cb527ae6 Mon Sep 17 00:00:00 2001 From: Keith Zantow Date: Thu, 23 Feb 2023 14:46:54 -0500 Subject: [PATCH] fix: decoding null apk metadata pullDependencies Signed-off-by: Keith Zantow --- syft/pkg/apk_metadata.go | 2 ++ syft/pkg/apk_metadata_test.go | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/syft/pkg/apk_metadata.go b/syft/pkg/apk_metadata.go index 104564883ca..21abd50df50 100644 --- a/syft/pkg/apk_metadata.go +++ b/syft/pkg/apk_metadata.go @@ -87,6 +87,8 @@ func (a *spaceDelimitedStringSlice) UnmarshalJSON(data []byte) error { } *a = s return nil + case nil: + return nil default: return fmt.Errorf("invalid type for string array: %T", obj) } diff --git a/syft/pkg/apk_metadata_test.go b/syft/pkg/apk_metadata_test.go index 8eaa210d736..a5e5f4121dd 100644 --- a/syft/pkg/apk_metadata_test.go +++ b/syft/pkg/apk_metadata_test.go @@ -98,6 +98,15 @@ func TestApkMetadata_UnmarshalJSON(t *testing.T) { Files: []ApkFileRecord{{Path: "/usr"}}, }, }, + { + name: "null pullDependencies", + input: `{ +"pullDependencies": null +}`, + want: ApkMetadata{ + Dependencies: nil, + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {