You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A file shorter than one page opens as a new empty database (read-write re-initializes it) #506
Found by the corrupt_file fuzz target (#387 PR B) in its first minutes.
What happens
A database file truncated to fewer than 4096 bytes (one page) opens without error as a new, empty database:
v3: FileBackend::open computes page_count = file_len / PAGE_SIZE, which is 0, so PersistentFactStorage::select_meta returns Opened::Fresh. A read-write open then runs init_empty and writes a fresh meta page over what is left of page 0. A read-only open shows an empty database.
main (v2.x): FileBackend::open treats file_len < PAGE_SIZE as a new file and writes a new header over it.
Either way, a damaged file is answered with wrong data (no facts, tx count 0) instead of an error, and the read-write case overwrites what was left of it.
Reproducer (fuzzer input, corrupt_file layout): 24 ae 08 00 00 00 ae 89. That is a read-write open of the template truncated to 2222 bytes, with no byte edits. Any length 1..4095 behaves the same.
Why it is not just a torn initial write
The only legitimate way to get a non-empty file under one page is a crash during the very first meta write of a brand-new database, and that file holds no data. A real database truncated by a bad copy, a full disk during a copy, or filesystem damage takes the same branch and is silently replaced.
Options
Refuse any file of 1..4095 bytes with a new STG code ("file shorter than one page"). A crash in the first write of a new database then needs the file deleted by hand. That is rare, and it is clearly reported.
Accept it as fresh only when the bytes present are a prefix of exactly what init_empty writes (generation 1 empty meta), or all zero. Refuse anything else.
Option 2 keeps crash-on-create recoverable and rejects everything else. Both apply to read-only opens as well.
A zero-length file stays a new database, as in SQLite.
Done when
Fix on v3, with a regression test in tests/ and the input above as a corrupt_file seed.
The corrupt_file target drops its temporary skip of sub-page lengths.
Decision (2026-10-10): option 2. A file of 1..4095 bytes is accepted as a new database only when its bytes are all zero or a prefix of exactly what init_empty writes (the generation-1 empty meta), the same rule is_torn_initial_meta already applies to a full page 0. Anything else is refused with a new STG code, for read-write and read-only opens. A zero-length file stays a new database.
Fixed in v2.0.5 (released 2026-10-11, PR #509): a file of 1–4,095 bytes is refused with STG-045 unless it is a torn first write. Also fixed on v3 for v3.0.0. Listed under "Fixed in v2.0.5" in #421.
Activity
adityamukho commentedon Oct 10, 2026
Decision (2026-10-10): option 2. A file of 1..4095 bytes is accepted as a new database only when its bytes are all zero or a prefix of exactly what
init_emptywrites (the generation-1 empty meta), the same ruleis_torn_initial_metaalready applies to a full page 0. Anything else is refused with a new STG code, for read-write and read-only opens. A zero-length file stays a new database.Merge pull request #508 from project-minigraf/fix/506-short-file
Merge pull request #509 from project-minigraf/fix/506-short-file-v2
release: v2.0.5
adityamukho commentedon Oct 11, 2026
Fixed in v2.0.5 (released 2026-10-11, PR #509): a file of 1–4,095 bytes is refused with
STG-045unless it is a torn first write. Also fixed onv3for v3.0.0. Listed under "Fixed in v2.0.5" in #421.