Repository navigation
fix(ruby): keep compound pessimistic patched versions - #2562
Open
sanchit955 wants to merge 1 commit into
Open
sanchit955 wants to merge 1 commit into
sanchit955 wants to merge 1 commit into
Conversation
ruby-advisory-db ships patched_versions entries such as "~> 2.0, >= 2.2.6.4". GemVersionRange.from_native expands the pessimistic requirement to >=2.0, <3 and appends >=2.2.6.4, so the combined list holds two >= lower bounds and validate_comparators rejects it; get_affected_packages logged the error and dropped the entry, silently losing the fixed version for that release line (159 entries in 99 real advisories, e.g. rack CVE-2023-27539 kept only >=3.0.6.1 and lost the 2.x-line fix). Parse the comma-separated parts and intersect them instead: keep the greatest lower bound and the smallest upper bound, so the entry above becomes >=2.2.6.4, <3. Specs that do not intersect, or that cannot be parsed, still raise ValueError and are skipped as before. Signed-off-by: Sanchit <dev.sanchit955@gmail.com>
This branch has not been deployed
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.
Fixes #2561
Problem
get_affected_packages(vulnerabilities/pipelines/v2_importers/ruby_importer.py) callsGemVersionRange.from_native(patched_version)+validate_comparatorson each patched spec. For a compound spec like"~> 2.0, >= 2.2.6.4",from_nativeexpands~> 2.0to>=2.0, <3and appends>=2.2.6.4, so the combined list holds two>=lower bounds andvalidate_comparatorsrejects it. The loop logs the error and skips the entry, so the fixed version for that release line is never recorded.Evidence
Scanned ruby-advisory-db (1,571 YAMLs, 1 Dec 2026): 159 entries in 99 advisories are exactly this shape (
"~> V, >= V", 71 distinct specs).['~> 2.0, >= 2.2.6.4', '>= 3.0.6.1']→ onlyvers:gem/>=3.0.6.1recorded pre-fix; post-fix bothvers:gem/>=2.2.6.4|<3andvers:gem/>=3.0.6.1.['~> 8.0.5, >= 8.0.5.2', '>= 8.1.4.1']→ only>=8.1.4.1pre-fix.The loss is partial: no advisory loses all its impacted packages, but fixed versions go missing from the stored data.
Fix
New helper
parse_patched_version_rangesplits the spec on "," and intersects the parts (greatest lower bound, smallest upper bound,!=exclusions kept,=handled; empty intersection → ValueError). It also catchesInvalidRequirementError(anAttributeError, not aValueError) and re-raises ValueError so the loop's existingexcept ValueErrorworks; non-string/empty specs raise ValueError instead of uncaught AttributeError/TypeError.unaffected_versionsis untouched — open #2537 owns that side.Tests
vulnerabilities/tests/pipelines/v2_importers/test_ruby_importer_v2.py(11 new + 4 pre-existing fixture tests). New tests fail pre-fix (advisory-level test verified on pristine main; helper tests fail at collection there since the helper does not exist).black --checkclean on both changed files.Signed-off-by: Sanchit dev.sanchit955@gmail.com