Skip to content

Commit 94dc496

Browse files
authored
chore: only extract versions from packages in the generator ecosystem (#957)
Cherry-picked from G-Rath/osv-detector#241 --- Currently the generators assume that all packages in an OSV are for their respective ecosystem which since they download ecosystem-specific databases is _mostly_ true, but there are a few OSVs that are for packages that exist across more than one ecosystem. This has not been a problem up until now because either the versions in such OSVs happen to be compatible with native ecosystem version parser or we're skipping invalid versions for legacy reasons, but now GHSA-5844-q3fc-56rh exists which has versions that are invalid in Ruby.
1 parent cbc9678 commit 94dc496

5 files changed

+18
-0
lines changed

scripts/generators/GenerateMavenVersions.java

+4
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ public static Map<String, List<String>> fetchPackageVersions() throws IOExceptio
9494
osvs.forEach(osv -> osv.getJSONArray("affected").forEach(aff -> {
9595
JSONObject affected = (JSONObject) aff;
9696

97+
if(affected.getJSONObject("package").getString("ecosystem").equals("Maven")) {
98+
return;
99+
}
100+
97101
String pkgName = affected.getJSONObject("package").getString("name");
98102

99103
if(!affected.has("versions")) {

scripts/generators/generate-cran-versions.R

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ extract_packages_with_versions <- function(osvs) {
2424

2525
for (osv in osvs) {
2626
for (affected in osv$affected) {
27+
if (affected$package$ecosystem != "CRAN") {
28+
next
29+
}
30+
2731
package <- affected$package$name
2832

2933
if (!(package %in% names(result))) {

scripts/generators/generate-debian-versions.py

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ def extract_packages_with_versions(osvs):
4747

4848
for osv in osvs:
4949
for affected in osv['affected']:
50+
if not affected['package']['ecosystem'].startswith('Debian'):
51+
continue
52+
5053
package = affected['package']['name']
5154

5255
if package not in dict:

scripts/generators/generate-packagist-versions.php

+4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ function fetchPackageVersions(): array
7979

8080
foreach ($osvs as $osv) {
8181
foreach ($osv['affected'] as $affected) {
82+
if ($affected['package']['ecosystem'] !== 'Packagist') {
83+
continue;
84+
}
85+
8286
$package = $affected['package']['name'];
8387

8488
if (!isset($packages[$package])) {

scripts/generators/generate-pypi-versions.py

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ def extract_packages_with_versions(osvs):
4040

4141
for osv in osvs:
4242
for affected in osv['affected']:
43+
if affected['package']['ecosystem'] != 'PyPI':
44+
continue
45+
4346
package = affected['package']['name']
4447

4548
if package not in dict:

0 commit comments

Comments
 (0)