-
Notifications
You must be signed in to change notification settings - Fork 370
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: parsing crash on malformed pnpm lockfile #1327
Merged
another-rex
merged 8 commits into
google:main
from
ivmeta:remotes/origin/pnpm-parse-fix
Oct 31, 2024
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
22be1d6
Update parse-pnpm-lock.go
ivmeta dc1c5ca
Added failing lockfile
ivmeta 79ed909
Return error on invalid package path
ivmeta ba76fb6
Fix go.mod golang version
ivmeta 23c7047
Update pkg/lockfile/parse-pnpm-lock_test.go
ivmeta cfbc0f1
Merge branch 'main' into remotes/origin/pnpm-parse-fix
ivmeta 9c21958
Merge branch 'main' into remotes/origin/pnpm-parse-fix
ivmeta a848fde
Merge branch 'main' into remotes/origin/pnpm-parse-fix
cuixq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
lockfileVersion: 5.4 | ||
|
||
specifiers: | ||
'@types/jsdom': ^20.0.1 | ||
axios: ^1.2.5 | ||
pinia: ^2.0.28 | ||
stream: 0.0.2 | ||
typescript: ~4.7.4 | ||
|
||
dependencies: | ||
axios: 1.2.5 | ||
pinia: 2.0.28_e7lp6ggkpgyi5vqd44m2kxvk6i | ||
stream: 0.0.2 | ||
|
||
devDependencies: | ||
'@types/jsdom': 20.0.1 | ||
npm-run-all: 4.1.5 | ||
|
||
packages: | ||
|
||
/@babel/helper-string-parser/7.19.4: | ||
resolution: {integrity: sha512-nHtDoQcuqFmwYNYPz3Rah5ph2p8PFeFCsZk9A/48dPc/rGocJ5J3hAAZ7pb76VWX3fZKu+uEr/FhH5jLx7umrw==} | ||
engines: {node: '>=6.9.0'} | ||
|
||
/@babel/helper-validator-identifier/7.19.1: | ||
resolution: {integrity: sha512-awrNfaMtnHUr653GgGEs++LlAvW6w+DcPrOliSMXWCKo597CwL5Acf/wWdNkf/tfEQE3mjkeD1YOVZOUV/od1w==} | ||
engines: {node: '>=6.9.0'} | ||
|
||
/@babel/parser/7.20.7: | ||
resolution: {integrity: sha512-T3Z9oHybU+0vZlY9CiDSJQTD5ZapcW18ZctFMi0MOAl/4BjFF4ul7NVSARLdbGO5vDqy9eQiGTV0LtKfvCYvcg==} | ||
engines: {node: '>=6.0.0'} | ||
hasBin: true | ||
dependencies: | ||
'@babel/types': 7.20.7 | ||
|
||
/@types/jsdom/20.0.1: | ||
resolution: {integrity: sha512-d0r18sZPmMQr1eG35u12FZfhIXNrnsPU/g5wvRKCUf/tOGilKKwYMYGqh33BNR6ba+2gkHw1EUiHoN3mn7E5IQ==} | ||
dependencies: | ||
'@types/node': 18.11.18 | ||
'@types/tough-cookie': 4.0.2 | ||
parse5: 7.1.2 | ||
dev: true | ||
|
||
[email protected]: | ||
resolution: {integrity: sha512-9pU/8mmjSSOb4CXVsvGIevN+MlO/t9OWtKadTaLuN85Gge3HGorUckgp8A/2FH4V4hJ7JuQ3LIeI7KAV9ITZrQ==} | ||
dependencies: | ||
follow-redirects: 1.15.2 | ||
form-data: 4.0.0 | ||
proxy-from-env: 1.1.0 | ||
transitivePeerDependencies: | ||
- debug | ||
dev: false | ||
|
||
/stream/0.0.2: | ||
resolution: {integrity: sha512-gCq3NDI2P35B2n6t76YJuOp7d6cN/C7Rt0577l91wllh0sY9ZBuw9KaSGqH/b0hzn3CWWJbpbW0W0WvQ1H/Q7g==} | ||
dependencies: | ||
emitter-component: 1.1.1 | ||
dev: false | ||
|
||
/typescript/4.7.4: | ||
resolution: {integrity: sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==} | ||
engines: {node: '>=4.2.0'} | ||
hasBin: true | ||
|
||
/pinia/2.0.28_e7lp6ggkpgyi5vqd44m2kxvk6i: | ||
resolution: {integrity: sha512-YClq9DkqCblq9rlyUual7ezMu/iICWdBtfJrDt4oWU9Zxpijyz7xB2xTwx57DaBQ96UGvvTMORzALr+iO5PVMw==} | ||
peerDependencies: | ||
'@vue/composition-api': ^1.4.0 | ||
typescript: '>=4.4.4' | ||
vue: ^2.6.14 || ^3.2.0 | ||
peerDependenciesMeta: | ||
'@vue/composition-api': | ||
optional: true | ||
typescript: | ||
optional: true | ||
dependencies: | ||
'@vue/devtools-api': 6.4.5 | ||
typescript: 4.7.4 | ||
vue: 3.2.45 | ||
vue-demi: [email protected] | ||
dev: false | ||
|
||
/http-proxy-agent/5.0.0: | ||
resolution: {integrity: sha512-n2hY8YdoRE1i7r6M0w9DIw5GgZN0G25P8zLCRQ8rjXtTU3vsNFBI/vWK/UIeE6g5MUUz6avwAPXmL6Fy9D/90w==} | ||
engines: {node: '>= 6'} | ||
dependencies: | ||
'@tootallnate/once': 2.0.0 | ||
agent-base: 6.0.2 | ||
debug: 4.3.4 | ||
transitivePeerDependencies: | ||
- supports-color | ||
dev: true |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -586,3 +586,13 @@ func TestParsePnpmLock_Files(t *testing.T) { | |
}, | ||
}) | ||
} | ||
|
||
func TestParsePnpmLock_Invalid(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you assert the packages that are expected to be extracted as part of the test? |
||
t.Parallel() | ||
|
||
_, err := lockfile.ParsePnpmLock("fixtures/pnpm/invalid.yaml") | ||
|
||
if err != nil { | ||
t.Errorf("Got unexpected error: %v", err) | ||
} | ||
} |
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.
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 give this a more descriptive name? it can still be terse, but currently "invalid" could mean a lot of things (the first that times to mind is that it's invalid YAML) - something like "with-invalid-path" would be enough
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.
Arguably the file is valid (I'm not an expert in pnpm lockfiles myself), but osv-scanner is failing to parse it correctly (and it crashes) on the [email protected] line.
This test file just validates that osv-scanner doesn't crash while reading it.
Happy to update the test case function / fixture file name to whatever you think captures this subtlety.
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.
My understanding is that this is an invalid key - while I'm also not an expect on pnpm lockfiles, I've not seen keys like this previously (if I had, then I'd have already covered this case in one of the 2-3 times I've effectively rewritten a part of this parser for a new lockfile version 😅) and it's also in a
semgrep
fixture called "pnpm-error-key".I think it is valid to call it
with-invalid-path
(or maybewith-invalid-package-path
would be even better 🤔)