fix(scan): cap per-file allocation via MaxFileSize to prevent memory DoS#2924
Open
BiswajeetRay7 wants to merge 1 commit into
Open
fix(scan): cap per-file allocation via MaxFileSize to prevent memory DoS#2924BiswajeetRay7 wants to merge 1 commit into
BiswajeetRay7 wants to merge 1 commit into
Conversation
Both filesystem scan (scan.go) and container image scan (osvscanner.go) constructed scalibr.ScanConfig without MaxFileSize. scalibr documents 0 as 'no limit', so 20+ lockfile/manifest extractors that io.ReadAll on input.Reader could allocate arbitrarily large memory for attacker-supplied files (repo files up to 2 GB via git-LFS, or unbounded container-image layer entries). Add defaultMaxFileSize = 512 MiB matching the image-layer scanner's MaxFileBytes and pass it to both ScanConfig sites. This aligns with the JAR extractor's existing defaultMaxZipBytes pattern. Refs: docs/migrating-from-scalibr.md:104 lists --max-file-size as 'Not yet available'. This change wires the default so the safeguard exists regardless of the CLI flag.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Both filesystem scan (
pkg/osvscanner/scan.go:240) and container image scan (pkg/osvscanner/osvscanner.go:321) constructscalibr.ScanConfigwithoutMaxFileSize. scalibr documents0as "no limit" (osv-scalibr/extractor/filesystem/filesystem.go:114), so 20+ lockfile/manifest extractors that callio.ReadAll(input.Reader)can allocate arbitrarily large memory for attacker-supplied files.Realistic attack sources:
actions/checkoutlfs: true)On GitHub-hosted runners (7 GB RAM), a single ~2 GB
package-lock.jsonorCargo.lockcan OOM-kill the scanner during JSON parse (JSON parsing typically allocates 3-5× file size).Fix
defaultMaxFileSize = 512 * 1024 * 1024(512 MiB) as a package-level constant, matchingosv-scalibr's image-layer scannerMaxFileBytesdefault.scalibr.ScanConfigsites.Aligns with the JAR extractor's existing
defaultMaxZipBytespattern (osv-scalibr/extractor/filesystem/language/java/archive/archive.go:52) — extending the same safe-default philosophy to file-level ingestion.Related
docs/migrating-from-scalibr.md:104currently lists--max-file-sizeas "Not yet available". This change wires the default so the safeguard exists regardless of whether the CLI flag lands.Testing
Existing test suite exercises files well under 512 MiB — no behavior change for real-world scans. Manual verify: repo with
Cargo.lock>512 MiB is now skipped (as documented byfilesystem.go:519-529whenmaxFileSize > 0).