fix: guard index-out-of-range panics in dependency parsers and amazon detector - #10994
Closed
donkk11 wants to merge 1 commit into
Closed
fix: guard index-out-of-range panics in dependency parsers and amazon detector#10994donkk11 wants to merge 1 commit into
donkk11 wants to merge 1 commit into
Conversation
… detector Six locations indexed strings.Fields(...)[0]/FieldsFunc(...)[0] without checking the slice was non-empty, panicking on malformed-but-parseable input (empty dependency strings, whitespace-only lines, empty bodies): - pkg/detector/ospkg/amazon/amazon.go: IsSupportedVersion (named in the issue) AND Detect (a second, identical occurrence not mentioned in the issue - found only by running the real reproduction end to end). - pkg/dependency/parser/python/pyproject/pyproject.go - pkg/dependency/parser/swift/cocoapods/parse.go - pkg/dependency/parser/hex/mix/parse.go - pkg/dependency/parser/ruby/bundler/parse.go Each guard follows the length-check-before-index pattern already used elsewhere in the codebase (bundler/parse.go's dependency-list function), skipping the malformed entry instead of crashing the whole scan. Verified against real reproductions: a rootfs whose /etc/system-release contains only "Amazon Linux" (no version), and a pyproject.toml with an empty dependency string - both previously panicked, both now exit 0. 5 new regression tests using the issue's own malformed inputs. All 5 packages' existing test suites still pass. Independently verified by a second AI (gpt-5.6-sol) under the Nkama Fact Benchmark protocol: rebuilt the binary itself, wrote its own adversarial probe (whitespace-only version strings, empty-list vs empty-string cocoapods entries, colon+comma-only mix lines - none panicked), and confirmed the bundler fix does not skip the later DEPENDENCIES section-header check in the same loop iteration. Fixes aquasecurity#10976 Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> Co-Authored-By: gpt-5.6-sol (adversarial verification) Signed-off-by: KK Nkama <kknkama@gmail.com>
|
|
Author
|
Closing this — I missed that #10978 (@123kaze) was already open and covering this issue when I started; that's on me for not checking linked PRs before building, only assignees. Having now compared both fixes: #10978 is the better one and should be the one that lands. Specifically:
Thanks for the reminder to check more carefully before starting next time. Appreciate #123kaze's work here. |
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.
Summary
Fixes #10976. Six locations indexed
strings.Fields(...)[0]/FieldsFunc(...)[0]without checking the slice was non-empty, panicking on malformed-but-parseable input and aborting the whole scan:pkg/detector/ospkg/amazon/amazon.go—IsSupportedVersion(named in the issue) andDetect(a second, identical occurrence not mentioned in the issue — found by running the real reproduction end to end, not just from the issue's list)pkg/dependency/parser/python/pyproject/pyproject.gopkg/dependency/parser/swift/cocoapods/parse.gopkg/dependency/parser/hex/mix/parse.gopkg/dependency/parser/ruby/bundler/parse.goEach guard follows the length-check-before-index pattern already used elsewhere in the codebase (bundler's own dependency-list function), skipping the malformed entry instead of crashing.
Verification
trivy rootfson a directory whose/etc/system-releasecontains onlyAmazon Linux(no version)trivy fson apyproject.tomlwithdependencies = ["flask>=1.0", ""]DEPENDENCIESsection-header checkTest plan
go test ./pkg/detector/ospkg/amazon/... ./pkg/dependency/parser/python/pyproject/... ./pkg/dependency/parser/swift/cocoapods/... ./pkg/dependency/parser/hex/mix/... ./pkg/dependency/parser/ruby/bundler/...