DevWeave logoDevWeave
CommunitiesDiscoverHelp ForumFeaturesWhy DevWeaveAI & Verification
Log inGet started
Back to Issue Discovery
ossf/cve-bin-tool #6163closedPythonPython

fix: R parser crashes with KeyError on versionless package records in renv.lock

Opened by @trackoor · Assignees: None

View on GitHub

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)

1,819 GitHub Stars

Claim Status & GitHub Signal

Unassigned, with 1 comment. Unassigned does not guarantee unclaimed—read comments and linked PRs first.

AI Issue Assessment · Grounded Analyzer
4.5 / 10 · 5–6 · Intermediate

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.

Skill Match Breakdown

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.

Log in to receive your free level-adapted Hint #1 grounded in this repository's files.

Skill-Gap Learning

Gap-Targeted
Learn Linux

Shell navigation, process inspection, pipes, and CLI debugging.

Addresses skill gap: CLI & Shell

Learn Code in Python

Core Python syntax, functions, control flow, and debugging basics.

Addresses skill gap: Python

Learn Object Oriented Programming in Python

Designing clean classes, encapsulation, and testable Python modules.

Addresses skill gap: Testing & pytest

Hands-On CodeCrafters Practice
Skill-Gap Challenge
Build your own Shell
Python

Parse commands, manage PATH lookups, pipes, and process execution.

Practice skill gap: Python

Build your own HTTP Server
Python

Handle raw TCP connections, HTTP parsing, headers, and concurrent routes.

Practice skill gap: Python

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) and 3.4.1 (main at 09539e71596c6777e4b73209e9271d2cce2f764a; still present at df5ca6b64a651a20407fa0f1d0d144db812f75f4)
  • 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)

@TarequeSyedCONTRIBUTOR
View comment →

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?

Peer Help Forum · ossf/cve-bin-tool #6163

Issue Troubleshooting Threads (0)

Ask Peers for Help

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.

Sign In

Contribution Workflow

Track your local progress before opening a pull request on GitHub.

Repository Context

Top Repository Paths

.gitattributes
[dir] .github
[dir] .github/ISSUE_TEMPLATE
.github/ISSUE_TEMPLATE/bug-report.md
.github/ISSUE_TEMPLATE/docstrings.md
.github/ISSUE_TEMPLATE/feat--new-checker-request-form.md
.github/ISSUE_TEMPLATE/feat-request.md
.github/ISSUE_TEMPLATE/mismatch-report.md
[dir] .github/PULL_REQUEST_TEMPLATE
.github/PULL_REQUEST_TEMPLATE/new_checker.md
[dir] .github/actions
[dir] .github/actions/spelling
.github/actions/spelling/README.md
.github/actions/spelling/advice.md
.github/actions/spelling/allow.txt
.github/actions/spelling/excludes.txt
.github/actions/spelling/expect.txt
.github/actions/spelling/only.txt
.github/actions/spelling/patterns.txt
.github/actions/spelling/reject.txt
.github/codecov.yml
.github/dependabot.yml
.github/scorecard.yml
[dir] .github/workflows

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
      • Using pre-commit to run linters automatically
      • Running isort by itself
      • Running black by itself
      • Running bandit by itself
      • Running mypy by itself
      • Running interrogate by itself
      • Other linting tools
    • Making a new branch & pull request
      • Commit message tips
      • Sharing your code with us
      • Checklist for a great pull request
    • Code Review
    • Style Guide for cve-bin-tool
      • String Formatting
    • [Making documen

... (truncated)

Advisory PR Assistant

Helps structure your PR description or unpack reviewer feedback. Does not perform GitHub actions.