Skip to content

Combine Ruby unaffected version ranges (#2536) - #2537

Open
kunaalxoxo wants to merge 1 commit into
aboutcode-org:mainfrom
kunaalxoxo:fix-ruby-unaffected-versions
Open

kunaalxoxo wants to merge 1 commit into
aboutcode-org:mainfrom
kunaalxoxo:fix-ruby-unaffected-versions

Conversation

@kunaalxoxo

Copy link
Copy Markdown

Fixes #2536

Problem

RubyImporterPipeline (get_affected_packages in vulnerabilities/pipelines/v2_importers/ruby_importer.py) iterated over unaffected_versions and appended a separate AffectedPackageV2 for each inverted entry. When an advisory had two or more unaffected_versions entries (such as gems/activerecord/CVE-2016-6317.yml with ["< 4.2.0", ">= 5.0.0"]), unfurl_version_range_v2 took their union across ImpactedPackage rows and marked unaffected gem releases as affected.

Fix

  • Added invert_unaffected_versions() and interval helpers to merge all unaffected_versions entries as a union of safe intervals and take their complement as a single canonical GemVersionRange.
  • Handled ruby-advisory-db edge cases including compound/~> ranges, isolated exact-version ranges, single excluded versions (!=), empty complements, None/whitespace entries, and InvalidRequirementError.
  • Kept patched_versions emitting fixed_version_range AffectedPackageV2 entries unchanged.

Tests

  • Added parametrized unit tests in vulnerabilities/tests/pipelines/v2_importers/test_ruby_importer_v2.py (test_get_affected_packages_combines_unaffected_versions).
  • Added end-to-end unfurl regression test test_ruby_multi_unaffected_versions_unfurl_does_not_mark_unaffected verifying that 4.1.16, 5.0.0, and 7.1.3 are not marked affected for CVE-2016-6317.

RubyImporterPipeline previously emitted a separate AffectedPackageV2
for each inverted entry in unaffected_versions. When an advisory had
two or more unaffected_versions entries, unfurl_version_range_v2 took
their union and marked unaffected releases as affected.

Unify all unaffected_versions entries into a single union of intervals
before complementing into one affected GemVersionRange, and add unit
and unfurl regression tests.

Signed-off-by: Kunaal Prabhakar Singh Lala <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 14:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ruby_importer_v2 splits multi-entry unaffected_versions into separate ImpactedPackage rows whose union marks unaffected gem versions as affected

2 participants