-
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(nodejs): fix infinite loop when package link from package-lock.json
file is broken
#6858
fix(nodejs): fix infinite loop when package link from package-lock.json
file is broken
#6858
Conversation
@@ -208,7 +216,8 @@ func (p *Parser) resolveLinks(packages map[string]Package) { | |||
} | |||
|
|||
workspaces := rootPkg.Workspaces | |||
for pkgPath, pkg := range packages { | |||
// Clone packages to avoid cases when we check already updated packages |
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.
Could you elaborate on that?
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.
We update packages
map inside of packages
loop.
trivy/pkg/dependency/parser/nodejs/npm/parse.go
Lines 232 to 235 in a2d1871
packages[resolvedPath] = pkg | |
// Delete the target package | |
delete(packages, pkgPath) |
this is bad practice.
When I tested broken link with empty resolved
field - this loop would endlessly update packages
, check them and we get out of memory
error.
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 change the comment to something like "Changing the map during the map iteration causes unexpected behavior" for clarity?
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.
Yeah, it make sense.
Updated in b8e52c4
@aqua-bot backport release/v0.52 |
…son` file is broken (#6858)
Backport PR created: #6888 |
Description
This PR fixes 2 cases:
Packages[x].resolved
is empty for link - we don't need to resolve this link.packages
map when resolving links to avoid cases when we updated package is parsed.Related issues
Checklist