/ View Ticket
Login
Ticket UUID: d8dc2b3a58cd5dc2918a1d4acbba4676a23ada4c
Title: Crash when the schema for sqlite_sequence is corrupt
Status: Fixed Type: Code_Defect
Severity: Severe Priority: Immediate
Subsystem: Unknown Resolution: Fixed
Last Modified: 2018-05-23 17:53:50
Version Found In: 3.23.1
User Comments:
drh added on 2018-05-23 15:28:51:

When the entry in the sqlite_master table that describes the sqlite_sequence is corrupted in various ways, subsequent writes to an autoincrement table result in an assertion fault or crash. Where are two ways to reproduce the problem from the CLI:

.open -new test.db
CREATE TABLE fake_sequence(name TEXT PRIMARY KEY,seq) WITHOUT ROWID;
PRAGMA writable_schema=on;
UPDATE sqlite_master SET
  sql=replace(sql,'fake_','sqlite_'),
  name='sqlite_sequence',
  tbl_name='sqlite_sequence'
 WHERE name='fake_sequence';
.open test.db
CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT);
INSERT INTO t1(b) VALUES('one');
.open -new test.db
CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT);
INSERT INTO t1(b) VALUES('one');
PRAGMA writable_schema=on;
UPDATE sqlite_master SET
  sql=replace(sql,'sqlite_','x_'),
  name='x_sequence',
  tbl_name='x_sequence'
 WHERE name='sqlite_sequence';
.open test.db
INSERT INTO t1(b) VALUES('two');

There are probably many other reproduction scripts.

The problem has existed ever since autoincrement tables were first added to SQLite version 3 with version 3.1.0 on 2005-01-21. This problem was reported on the SQLite users mailing list.