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

Syft fileresolver.containsPath allocates unnecessarily #3729

Closed
yoav-orca opened this issue Mar 13, 2025 · 0 comments · Fixed by #3730
Closed

Syft fileresolver.containsPath allocates unnecessarily #3729

yoav-orca opened this issue Mar 13, 2025 · 0 comments · Fixed by #3730
Labels
bug Something isn't working

Comments

@yoav-orca
Copy link
Contributor

What happened:
I'm using syft to generate an SBOM for container images, we are seeing OOM conditions due to a lot of heap memory.
Image

All the allocations are coming from this line:
https://github.com/anchore/syft/blob/main/syft/internal/fileresolver/path_skipper.go#L146

Changing it from the original to this:

func containsPath(p1, p2 string) bool {
	p1Clean := simpleClean(p1)
	p2Clean := simpleClean(p2)
	if p1Clean == p2Clean {
		return true
	}
	if !strings.HasPrefix(p1Clean, p2Clean) {
		return false
	}

	// Check if the next character after prefix is '/'
	return len(p1Clean) > len(p2Clean) && p1Clean[len(p2Clean)] == '/'
}

Reduces peak memory.

What you expected to happen:

I expected the compiler to be smart enough not to make a memory allocation at all.

Steps to reproduce the issue:
Use syft.CreateSBOM to generate an SBOM.

Anything else we need to know?:

Environment:

  • Output of syft version: I'm using it as a library github.com/anchore/syft v1.18.2-0.20250108175148-b4e7b64d5ce0
  • OS (e.g: cat /etc/os-release or similar):
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
@yoav-orca yoav-orca added the bug Something isn't working label Mar 13, 2025
@wagoodman wagoodman linked a pull request Mar 13, 2025 that will close this issue
4 tasks
@github-project-automation github-project-automation bot moved this to Done in OSS Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants