-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
fix(report): fix error with unmarshal of ExperimentalModifiedFindings
#7463
fix(report): fix error with unmarshal of ExperimentalModifiedFindings
#7463
Conversation
5e29be3
to
5fff7ac
Compare
This problem will be solved after aquasecurity/trivy-db#436. |
I'll also open another PR to fix this line. trivy/pkg/fanal/types/package.go Line 81 in 5c37361
|
pkg/types/finding.go
Outdated
raw := struct { | ||
Type FindingType `json:"Type"` | ||
Status FindingStatus `json:"Status"` | ||
Statement string `json:"Statement"` | ||
Source string `json:"Source"` | ||
Finding json.RawMessage `json:"Finding"` | ||
}{} | ||
|
||
if err := json.Unmarshal(data, &raw); err != nil { | ||
return err | ||
} | ||
|
||
m.Type = raw.Type | ||
m.Status = raw.Status | ||
m.Statement = raw.Statement | ||
m.Source = raw.Source |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we refactor as below?
type Alias ModifiedFinding
aux := &struct {
Finding json.RawMessage `json:"Finding"`
*Alias
}{
Alias: (*Alias)(m),
}
cf.
trivy/pkg/fanal/types/package.go
Lines 97 to 121 in 5c37361
// UnmarshalJSON customizes the JSON decoding of PkgIdentifier. | |
func (id *PkgIdentifier) UnmarshalJSON(data []byte) error { | |
type Alias PkgIdentifier | |
aux := &struct { | |
PURL string `json:",omitempty"` | |
*Alias | |
}{ | |
Alias: (*Alias)(id), | |
} | |
if err := json.Unmarshal(data, &aux); err != nil { | |
return err | |
} | |
if aux.PURL != "" { | |
p, err := packageurl.FromString(aux.PURL) | |
if err != nil { | |
return err | |
} else if len(p.Qualifiers) == 0 { | |
p.Qualifiers = nil | |
} | |
id.PURL = &p | |
} | |
return nil | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in 38b0d2b
0613621
to
38b0d2b
Compare
ExperimentalModifiedFindings
in json
formatExperimentalModifiedFindings
…-modified-finding
Signed-off-by: knqyf263 <knqyf263@gmail.com>
@DmitriyLewen Do you think we want to backport this fix? I'm not sure this is a critical issue because this problem happens only when |
hmm... I'm not sure about that This is really quite rare case |
@aqua-bot backport release/v0.55 |
…s` (#7463) Signed-off-by: knqyf263 <knqyf263@gmail.com> Co-authored-by: knqyf263 <knqyf263@gmail.com>
Backport PR created: #7492 |
Description
Fix error with unmarshal of ExperimentalModifiedFindings (e.g. in
convert
mode)➜ trivy -d convert --show-suppressed --exit-code 0 reports/trivyFull.json ... 2024-09-09T10:22:22+06:00 FATAL Fatal error - json decode error: github.com/aquasecurity/trivy/pkg/commands/convert.Run github.com/aquasecurity/trivy/pkg/commands/convert/run.go:32 - json: cannot unmarshal object into Go struct field ModifiedFinding.Results.ExperimentalModifiedFindings.Finding of type types.finding
Related issues
Checklist