Skip to content
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

Merged
merged 4 commits into from
Jun 10, 2024

Conversation

DmitriyLewen
Copy link
Contributor

Description

This PR fixes 2 cases:

  1. When Packages[x].resolved is empty for link - we don't need to resolve this link.
  2. Don't overwrite packages map when resolving links to avoid cases when we updated package is parsed.

Related issues

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@DmitriyLewen DmitriyLewen self-assigned this Jun 5, 2024
@DmitriyLewen DmitriyLewen marked this pull request as ready for review June 5, 2024 06:32
@@ -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
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

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.

Copy link
Collaborator

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?

Copy link
Contributor Author

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

@knqyf263 knqyf263 added this pull request to the merge queue Jun 10, 2024
Merged via the queue into aquasecurity:main with commit cf5aa33 Jun 10, 2024
12 checks passed
@DmitriyLewen DmitriyLewen deleted the fix-npm/link-resolve branch June 10, 2024 07:21
@DmitriyLewen
Copy link
Contributor Author

@aqua-bot backport release/v0.52

@aqua-bot
Copy link
Contributor

Backport PR created: #6888

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(npm): runtime: out of memory
3 participants