Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions vulnerabilities/importers/gentoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,33 @@ def affected_and_safe_purls(affected_elem):
purl = PackageURL(type="ebuild", name=pkg_name, namespace=pkg_ns)
safe_versions, affected_versions = GentooImporter.get_safe_and_affected_versions(pkg)

# for version in safe_versions:
# constraints.append(
# VersionConstraint(version=GentooVersion(version), comparator="=").invert()
# )

# for version in affected_versions:
# constraints.append(
# VersionConstraint(version=GentooVersion(version), comparator="=")
# )

def clean_ver(v):
# removes ":something" which univers rejects
return v.split(":", 1)[0]
Copy link
Collaborator

@ziadhany ziadhany Dec 12, 2025

Choose a reason for hiding this comment

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

Can you explain in more detail what the main error is there? If this is a univers bug, we can fix it in univers or we can ignore and log the invalid version if it truly is invalid.

I think we should not clean the version in VulnerableCode instead, we should use univers library to do this, or just log the invalid version and skip it.

Copy link
Author

Choose a reason for hiding this comment

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

Hey there, yeah so according to me the versions having ':'were getting rejected, that's why I performed a cleaning sort of function. And yes I think we can use the fix in univers .
if you want then I can give it a try to fix the same in univers

Copy link
Collaborator

Choose a reason for hiding this comment

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

@Arka-Saha OK, let's just log the invalid version without cleaning it so the importer can run without any issues . Then create an issue in the univers library with all invalid versions and give it a try.


for version in safe_versions:
constraints.append(
VersionConstraint(version=GentooVersion(version), comparator="=").invert()
)
try:
v_obj = GentooVersion(version)
except Exception:
v_obj = GentooVersion(clean_ver(version))
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should avoid general exceptions

constraints.append(VersionConstraint(version=v_obj, comparator="=").invert())

for version in affected_versions:
constraints.append(
VersionConstraint(version=GentooVersion(version), comparator="=")
)
try:
v_obj = GentooVersion(version)
except Exception:
v_obj = GentooVersion(clean_ver(version))
constraints.append(VersionConstraint(version=v_obj, comparator="="))

if not constraints:
continue
Expand Down
Loading