8000 Empty source during decoding an SBOM document should not be fatal by wagoodman · Pull Request #3791 · anchore/syft · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Empty source during decoding an SBOM document should not be fatal #3791

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion syft/format/syftjson/model/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func (s *Source) UnmarshalJSON(b []byte) error {
func unpackSrcMetadata(s *Source, unpacker sourceUnpacker) error {
rt := sourcemetadata.ReflectTypeFromJSONName(s.Type)
if rt == nil {
return fmt.Errorf("unable to find source metadata type=%q", s.Type)
// in cases where we are converting from an SBOM without any source information, we don't want this to be fatal
return nil
}

val := reflect.New(rt).Interface()
Expand Down
9 changes: 9 additions & 0 deletions syft/format/syftjson/model/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ func TestSource_UnmarshalJSON(t *testing.T) {
expected *Source
wantErr require.ErrorAssertionFunc
}{
{
name: "empty",
input: []byte(`{
"id": "",
"type": "",
"metadata": null
}`),
expected: &Source{},
},
{
name: "directory",
input: []byte(`{
Expand Down
Loading
0