Repository navigation
Conversation
a162daa to
26d6a3b
Compare
Signed-off-by: Gowri <gowri21115@gmail.com>
sanchit955
left a comment
There was a problem hiding this comment.
Tested this locally against the PR head (26d6a3b): the full test_gitlab_importer_v2.py file passes (9/9), and with the importer change reverted the new test fails with the exact yaml.composer.ComposerError: expected a single document in the stream from #2523, so the test pins the fix. I also probed saneyaml.load directly: a multi-document file raises ComposerError and a plain syntax error raises ParserError, both subclasses of yaml.YAMLError, so the except clause covers both. Returning None fits the existing contract — collect_advisories already logs and skips a falsy return, so one bad file no longer fails the pipeline. black 24.3.0 and isort 5.10.1 (the repo-pinned versions) are clean on both changed files.
Two small follow-ups, neither blocking:
- #2523 also asks for the malformed advisory to be reported upstream — this PR skips the file (logged at ERROR), so that part still needs someone to file it with the GitLab advisories repo.
- The test pins the multi-document case; a plain YAML syntax error goes through the same except but has no test pinning it — a second malformed-input case in the test would cover it.
Jean-Regis-M
left a comment
There was a problem hiding this comment.
Tested 26d6a3b: test_gitlab_importer_v2.py passes (9), and with gitlab_importer.py from the parent commit the new test fails with the same ComposerError as #2523, so it pins the crash.
One thing about the file that triggered this, though. npm/reasonix/CVE-2026-102437.yml (still the same on advisories-community main) isn't two advisories. It's one complete advisory with a stray --- as its last line:
>>> docs = list(yaml.safe_load_all(open("CVE-2026-102437.yml")))
>>> len(docs), type(docs[0]).__name__, docs[1]
(2, 'dict', None)
>>> sorted(docs[0])[:6]
['affected_range', 'affected_versions', 'cvss_v3', 'cwe_ids', 'date', 'description']So with this change the pipeline no longer fails, but it also drops a valid advisory (CVE-2026-102437, CVSS 7.8, CWE-78) every run until upstream fixes the file. Loading with safe_load_all and using the document when exactly one of them is non-empty would import it. Real multi-advisory files, or anything that still fails to parse, would keep the log-and-skip path you added. The test fixture (extra_doc: true as a second document) covers the second case, but not the trailing-separator case that actually happened.
Small things:
- A skipped file is logged twice: once in
parse_gitlab_advisory("failed to parse YAML") and once incollect_advisories("Failed to parse advisory from …"). - Other v2 importers load YAML the same way with no guard (
golang_vulndb_importer,istio_importer,oss_fuzz,project_kb_statements_importer,pypa_importer), so one bad upstream file would stop those pipelines too. Probably a separate issue, but worth knowing.
Use yaml.load_all with saneyaml.SaneLoader and ignore empty documents so advisories with a trailing '---' separator are parsed cleanly while multi-document or malformed YAML files still log an error and are skipped. Fixes aboutcode-org#2523 Signed-off-by: Gowri <gowri21115@gmail.com>
|
@sanchit955 Thanks for testing this locally and for the helpful suggestions! In Also, I'd be happy to open an upstream issue/MR on |
|
@Jean-Regis-M Thanks for the thorough review and for catching that In |
Fixes #2523.
yaml.YAMLErrorwhen loading YAML files withsaneyaml.load()inparse_gitlab_advisory, log the error, and returnNonesocollect_advisoriesskips the malformed file instead of failing the pipeline.test_parse_gitlab_advisory_with_malformed_yaml) covering multi-document / malformed YAML files.