fix: R parser crashes with KeyError on versionless package records in renv.lock
Opened by @trackoor · Assignees: None
Solve & Merge Reward: Up to +300 XP & +60 Coins
+30 XP on PR open · +180 XP & +60 coins on merge · +90 star XP (1,819 stars)
Claim Status & GitHub Signal
Unassigned, with 1 comment. Unassigned does not guarantee unclaimed—read comments and linked PRs first.
Estimated from issue labels (none), Python context, and discussion depth. There are 1 GitHub comments to review for maintainer clarifications. Note: this is an estimate, not a guarantee.
What It's About
fix: R parser crashes with KeyError on versionless package records in renv.lock. Description When scanning an R renv.lock file, RParser.run_checker() assumes every entry in "Packages" has a "Version" key. In renv's [lockfile JSON Schema](https://github.com/rstudio/renv/blob/main/inst/schema/draft-07.renv.lock.schema.json), only "Package" i
Why It Matters
Resolving #6163 improves reliability and developer experience in ossf/cve-bin-tool.
Expected Outcome
A focused pull request addressing #6163 with relevant checks or tests verified locally.
Log in to compare this issue's requirements against your profile skills. Required concepts: Python, Testing & pytest, CLI & Shell, Data Structures & Algorithms, Technical Documentation.
Progressive AI Hints
Hint #1 is always free and calibrated to your experience level. Extra hints unlock with coins without spoiling the full solution.
Skill-Gap Learning
Shell navigation, process inspection, pipes, and CLI debugging.
Addresses skill gap: CLI & Shell
Core Python syntax, functions, control flow, and debugging basics.
Addresses skill gap: Python
Designing clean classes, encapsulation, and testable Python modules.
Addresses skill gap: Testing & pytest
Issue Description
Description
When scanning an R renv.lock file, RParser.run_checker() assumes every entry in "Packages" has a "Version" key. In renv's lockfile JSON Schema, only "Package" is required on package records, and renv produces valid versionless entries via renv::record("bioc::Biobase", enrich = FALSE) (or plain renv::record("bioc::Biobase") in renv < 1.2.3, or a list record passed to renv::record()) that renv::restore() accepts. Encountering one such entry raises KeyError: 'Version' and aborts the scan, dropping any versioned packages in the same lockfile or directory.
To reproduce
Save a renv.lock produced by renv 1.3.1 (Rscript -e 'dir.create("/tmp/rproj"); renv::snapshot(project = "/tmp/rproj", prompt = FALSE); renv::record("bioc::Biobase", enrich = FALSE, project = "/tmp/rproj")') and run cve-bin-tool:
mkdir -p /tmp/rproj
cat > /tmp/rproj/renv.lock <<'EOF'
{
"R": {
"Version": "4.6.2",
"Repositories": [
{
"Name": "CRAN",
"URL": "https://cloud.r-project.org"
}
]
},
"Packages": {
"Biobase": {
"Package": "Biobase",
"Source": "Bioconductor"
},
"renv": {
"Package": "renv",
"Version": "1.3.1",
"Source": "Repository",
"Repository": "CRAN"
}
}
}
EOF
cve-bin-tool --no-scan -q /tmp/rproj/renv.lock
(On v3.4, where --no-scan is not present, run cve-bin-tool --offline -q /tmp/rproj/renv.lock with a populated local CVE cache or cve-bin-tool /tmp/rproj/renv.lock.)
Actual output:
Traceback (most recent call last):
...
File ".../cve_bin_tool/version_scanner.py", line 306, in scan_file
for scan_info in parse(
File ".../cve_bin_tool/parsers/parse.py", line 98, in parse
yield from parser.run_checker(filename)
File ".../cve_bin_tool/parsers/r.py", line 63, in run_checker
version = content["Packages"][package]["Version"]
KeyError: 'Version'
Expected behaviour: Biobase (which has no pinned version) is skipped without raising KeyError, and scanning continues so renv 1.3.1 and any other files in the scan target are still processed.
Version/platform info
- Version of CVE-bin-tool:
3.4(PyPI release) and3.4.1(mainat09539e71596c6777e4b73209e9271d2cce2f764a; still present atdf5ca6b64a651a20407fa0f1d0d144db812f75f4) - Installed from: PyPI (
pip install cve-bin-tool==3.4) and GitHub (main) - Operating System: Debian GNU/Linux 12 (bookworm), x86_64 (
6.1.0-56-cloud-amd64) - Python version: Python 3.11.2
Anything else?
In cve_bin_tool/parsers/r.py (line 64 on current main), RParser.run_checker() indexes content["Packages"][package]["Version"] directly without guarding for a missing key, similar to the versionless lockfile entry crashes fixed in SwiftParser (#6038) and DartParser (#6043).
Credit: https://ucsbplse.github.io/
Linked Pull Requests (0)
No linked or cross-referenced pull requests detected via GitHub timeline. Check comments below for informal claims before starting.
GitHub Comments (1)
Hi, I'd like to take a look at this issue and submit a PR for it!
I checked the ../parsers/r.py and the root cause is,
In cve_bin_tool/parsers/r.py, RParser.run_checker() directly accesses metadata["Version"] when iterating through packages in renv.lock . However, per the renv lockfile specification, "Version" is optional (e.g., unenriched records created via renv::record(..., enrich = FALSE)), which causes a KeyError crash and that is the reason, the scans are aborted.
Hence, we can fix it by: • Safely retrieving "Version" using .get("Version") in cve_bin_tool/parsers/r.py (along with a quick isinstance(metadata, dict) guard) and skipping any package records where the version is missing or empty.
• Adding a unit test in test/test_parser.py to verify that versionless package entries are skipped cleanly while valid versioned entries are still parsed. Is this thinking for the implementation correct? If no, can you kindly guide me. If yes, Can you please assign me this issue?
Issue Troubleshooting Threads (0)
No troubleshooting threads opened for this issue yet. If you hit a test, build, or navigation blocker, post what you've tried so fellow contributors can help.
PR Verification & Rewards
Sign in and link GitHub to verify your PR against this issue and earn XP + coins.
Contribution Workflow
Track your local progress before opening a pull request on GitHub.
Repository Context
Top Repository Paths
CONTRIBUTING.md Excerpt
CVE Binary Tool Contributor Guide
The CVE Binary Tool team participates in a few events every year that are aimed at new people in open source. This guide is meant to help people get over the initial hurdle of figuring out how to use git and make a contribution.
If you've already contributed to other open source projects, contributing to the CVE Binary Tool project should be pretty similar and you can probably figure it out by guessing. Experienced contributors might want to just skip ahead to the checklist for a great pull request But if you've never contributed to anything before, or you just want to see what we consider best practice before you start, this is the guide for you!
- CVE Binary Tool Contributor Guide
- Imposter syndrome disclaimer
- Code of Conduct
- Development Environment
- Getting and maintaining a local copy of the source code
- Choosing a version of python
- Setting up a virtualenv
- Installing dependencies
- Running your local copy of CVE Binary Tool
- Help, my checkers aren't loading
- Running tests
- Running linters
- Making a new branch & pull request
- Code Review
- Style Guide for cve-bin-tool
- [Making documen
... (truncated)
Advisory PR Assistant
Helps structure your PR description or unpack reviewer feedback. Does not perform GitHub actions.