SQLite User Forum

Assertion failure due to invalid Btree Cursor
Login

Assertion failure due to invalid Btree Cursor

(1) By Song Liu (songliu) on 2023-04-05 20:45:17 [source]

I found an assertion failure while SQLite (latest, 68a1a837493a0bc5) executes the following queries.

CREATE TABLE v0 (c1 PRIMARY KEY);
CREATE VIRTUAL TABLE v5 USING fts5(0);
DELETE FROM main.v5;
INSERT INTO v0 VALUES (0);
CREATE VIEW v7 AS SELECT c1 FROM v0 WHERE ((0,0) IN (SELECT 0, LAG(0) OVER (PARTITION BY 0) FROM v5), 0) < (c1,0);
SELECT max(c1) FROM v7;

Here are the outputs:

sqlite3: sqlite3.c:97064: sqlite3VdbeExec: Assertion `sqlite3BtreeCursorIsValid(pCur)' failed.
[1]    1469915 abort      ./sqlite3 < poc

Here is the result of bisecting:

 13 BAD     2021-07-16 22:43:00 85ddaf1b59a19cbd
 14 GOOD    2021-07-16 17:11:21 56b0f5418dad34d1 CURRENT

The assertion failure may be caused by the optimizations. SQLite crashes by default with all optimizations enabled. If I disable the SQLITE_MinMaxOpt optimization, SQLite works well.

.testctrl optimizations 0x00010000;

My compilation flags:

    export CFLAGS="-g -O0 -DSQLITE_DEBUG 
                -DSQLITE_ENABLE_TREETRACE 
                -DSQLITE_ENABLE_WHERETRACE
                -DSQLITE_ENABLE_CURSOR_HINTS 
                -DSQLITE_COUNTOFVIEW_OPTIMIZATION 
                -DSQLITE_ENABLE_STAT4"