database disk image is malformed (virtual table)
SQLITE_CORRUPT_VTAB (extended code 267) is returned by a virtual table implementation when it detects that its underlying data store is corrupted or returns data that violates the expected schema contract. Unlike SQLITE_CORRUPT which indicates B-tree file corruption, SQLITE_CORRUPT_VTAB is generated by the virtual table module itself — such as FTS5 detecting inconsistency in its shadow tables.
- 1An FTS5 or FTS4 full-text search index whose shadow tables are out of sync with the main content table
- 2A custom virtual table extension detecting internal inconsistency in its backing store
- 3Manual edits to shadow tables (fts5_data, fts5_config) that break internal invariants
An FTS5 index shadow table is manually corrupted.
import sqlite3
conn = sqlite3.connect(':memory:')
conn.execute("CREATE VIRTUAL TABLE docs USING fts5(title, body)")
conn.execute("INSERT INTO docs VALUES ('Hello', 'World')")
# Corrupt the FTS5 internal tables directly:
conn.execute("DELETE FROM docs_data") # removes B-tree pages
conn.execute("SELECT * FROM docs WHERE docs MATCH 'Hello'")expected output
sqlite3.DatabaseError: database disk image is malformed
Fix
Rebuild the FTS5 index
WHEN When FTS5 shadow tables are out of sync.
import sqlite3
conn = sqlite3.connect('mydb.db')
conn.execute("INSERT INTO docs(docs) VALUES('rebuild')")
conn.commit()Why this works
The special INSERT ... VALUES('rebuild') command instructs FTS5 to reconstruct all its shadow tables from the main content table, correcting any inconsistencies.
✕ Manually edit FTS5 or FTS4 shadow tables
These tables use internal binary formats and B-tree structures. Any manual edit will almost certainly corrupt the index and trigger SQLITE_CORRUPT_VTAB.
SQLITE_CORRUPT_VTAB extended code formalised to distinguish virtual table corruption from file-level B-tree corruption.
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev