Skip to content

fix(gentoo): skip entries with no usable version range - #2521

Open
sanchit955 wants to merge 1 commit into
aboutcode-org:mainfrom
sanchit955:fix/gentoo-empty-version-range
Open

sanchit955 wants to merge 1 commit into
aboutcode-org:mainfrom
sanchit955:fix/gentoo-empty-version-range

Conversation

@sanchit955

@sanchit955 sanchit955 commented Nov 24, 2026 •

Copy link
Copy Markdown

Problem

The gentoo importer builds a version range from whatever constraints it parsed, even when that list is empty. An unparsable GLSA version (e.g. 1.0*) produces EbuildVersionRange(constraints=[]), which serializes as vers:ebuild/. VersionRange.from_string rejects that string, so the affected package is dropped (to None) on every AdvisoryDataV2.from_dict round-trip — the exact error reported in #2387.

The apache_httpd half of #2387 is addressed the same way in #2392 (still open); the gentoo half was never fixed.

A second, related defect in the same path: an empty version element (<vulnerable range="lt"/>) passes None into GentooVersion, raising an uncaught AttributeError that kills the whole gentoo import run instead of skipping one entry.

Fix

  • In process_file: build the range only when constraints are non-empty; when there is no usable range, log and skip the entry — mirroring the apache_httpd fix for Invalid version range in apache_httpd and gentoo advisory #2387.
  • In build_constraints: skip (and log) constraint pairs with a missing version before parsing, so an empty element can no longer crash the run.

Trade-off

Skipping the entry means the package is not recorded as affected for that GLSA entry — the same trade-off #2392 made for apache_httpd. A deeper fix in AffectedPackageV2.from_dict (tolerate a None range instead of dropping the package) would be a behaviour change beyond the importer; flagging it here for maintainer decision rather than bundling it.

Tests

  • vulnerabilities/tests/pipelines/v2_importers/test_gentoo_importer_v2.py: 5 passed (3 existing + 2 new).
    • test_gentoo_invalid_version_does_not_build_empty_range: invalid version → entry skipped, unaffected entry kept.
    • test_gentoo_empty_version_element_does_not_crash: empty <vulnerable/> element → no crash, entry skipped.
    • Both new tests fail on unmodified main (verified via stash).
  • black --check clean on both changed files.

Fixes the gentoo half of #2387.

An unparsable GLSA version produced an EbuildVersionRange with no
constraints, which serializes as 'vers:ebuild/'. VersionRange.from_string
rejects that string, so the affected package was dropped on round-trip.
Skip the entry instead, mirroring the apache_httpd fix for aboutcode-org#2387. Also
guard missing version text: an empty version element previously raised
an uncaught AttributeError from GentooVersion(None) and killed the run.

Signed-off-by: Sanchit <dev.sanchit955@gmail.com>
@nikolya-ctrl

Copy link
Copy Markdown

Tested this locally (WSL, Python 3.13, PostgreSQL 18):

  • On this branch, test_gentoo_importer_v2.py gives 5 passed.
  • With gentoo_importer.py switched back to main but the new test file kept, the two new tests fail (test_gentoo_invalid_version_does_not_build_empty_range and test_gentoo_empty_version_element_does_not_crash) and the 3 existing ones still pass.

So both new tests do catch the problems on main, and the fix makes them pass. Looks good to me.

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.

2 participants