From 20381538dc8bc0e98ec4cf9990227dcb80f19862 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 3 Nov 2026 15:06:57 +0100 Subject: [PATCH] fix(security): report truncated OSV downloads and state what a warn verdict means A truncated chunked OSV download raises http.client.IncompleteRead, an HTTPException rather than an OSError, so it skipped the .part cleanup and the error line; the handler now catches both. The runtime check's warn summary no longer claims the mirror scan tracks every warning, since host findings and images outside the mirror never reach it. Co-Authored-By: Claude Opus 5.5 --- roles/sys-ctl-hlth-runtime/files/python/script.py | 2 +- tests/unit/python/utils/security/test_database.py | 13 +++++++++++++ utils/security/database.py | 3 ++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/roles/sys-ctl-hlth-runtime/files/python/script.py b/roles/sys-ctl-hlth-runtime/files/python/script.py index 11fd7c2966..252b4e8a96 100755 --- a/roles/sys-ctl-hlth-runtime/files/python/script.py +++ b/roles/sys-ctl-hlth-runtime/files/python/script.py @@ -1738,7 +1738,7 @@ def main(argv=None) -> int: elif warned: print( f"⚠️ {len(warned)} vulnerability finding(s) mapped to warn; " - "the daily mirror scan tracks them as issues." + "they do not fail this check." ) else: print( diff --git a/tests/unit/python/utils/security/test_database.py b/tests/unit/python/utils/security/test_database.py index 0c0af335c9..ca38ff0b66 100644 --- a/tests/unit/python/utils/security/test_database.py +++ b/tests/unit/python/utils/security/test_database.py @@ -1,5 +1,6 @@ from __future__ import annotations +import http.client import os import tempfile import time @@ -82,6 +83,18 @@ class TestFetchDatabases(_Root): self.assertIn("osv Ubuntu: timed out", errors) self.assertEqual(list(ubuntu.iterdir()), []) + def test_a_truncated_chunked_osv_download_leaves_no_zip_and_is_reported(self): + def fetch(url, destination): + destination.write_bytes(b"trunc") + raise http.client.IncompleteRead(b"trunc", 1024) + + errors = database.fetch_databases(P, self.root, ["osv"], None, fetch) + ubuntu = self.root / "osv" / "osv-scalibr" / "Ubuntu" + self.assertTrue( + any(error.startswith("osv Ubuntu: IncompleteRead") for error in errors) + ) + self.assertEqual(list(ubuntu.iterdir()), []) + class TestStale(_Root): def test_a_missing_database_is_stale(self): diff --git a/utils/security/database.py b/utils/security/database.py index b41aa35946..078e912a9a 100644 --- a/utils/security/database.py +++ b/utils/security/database.py @@ -3,6 +3,7 @@ from __future__ import annotations import fcntl +import http.client import os import shutil import time @@ -80,7 +81,7 @@ def fetch_databases( partial = zip_file.with_name(f"{zip_file.name}.part") try: fetch(osv_url(zip_file.parent.name), partial) - except OSError as exc: + except (OSError, http.client.HTTPException) as exc: partial.unlink(missing_ok=True) errors.append(f"osv {zip_file.parent.name}: {exc}") continue