From a6daf917ad2900a265af83c67e2c831668b22226 Mon Sep 17 00:00:00 2001 From: Mark Gregory Date: Fri, 27 Nov 2026 18:01:12 +0000 Subject: [PATCH] Reject empty SQLite backup artifacts during verification --- core/dev3/database.py | 2 ++ tests/unit/test_dev3_database.py | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/core/dev3/database.py b/core/dev3/database.py index 57169d5..20a5d19 100644 --- a/core/dev3/database.py +++ b/core/dev3/database.py @@ -84,6 +84,8 @@ class SandboxDatabase: if db.execute("PRAGMA integrity_check").fetchall() != [("ok",)]: raise DatabaseIdentityError("Backup integrity check failed") digest, size = checksum(path) + if size == 0: + raise DatabaseIdentityError("SQLite backup is empty") result = { "backup_id": identifier, "driver": "sqlite", "database": "acceptance", "username": "local_fixture", "container": "local_fixture", diff --git a/tests/unit/test_dev3_database.py b/tests/unit/test_dev3_database.py index 7a74fed..eafe601 100644 --- a/tests/unit/test_dev3_database.py +++ b/tests/unit/test_dev3_database.py @@ -1,6 +1,7 @@ import sqlite3 import tempfile import unittest +import uuid from contextlib import closing from pathlib import Path @@ -26,3 +27,15 @@ class DatabaseTests(unittest.TestCase): db.path.touch(mode=0o600) with self.assertRaises(DatabaseIdentityError): db.check() + + def test_rejects_empty_backup_left_after_interruption(self): + with tempfile.TemporaryDirectory() as directory: + root = Path(directory).resolve() + db = SandboxDatabase(root) + identifier = uuid.uuid4().hex + backup = root / identifier + backup.mkdir(mode=0o700) + path = backup / "database.sqlite" + path.touch(mode=0o600) + with self.assertRaisesRegex(DatabaseIdentityError, "SQLite backup is empty"): + db.verify(identifier)