Sqlightning segfaults on certain selects
The following SQL results in a segfault from sqlightning. The last SELECT
from TableB should return an empty result set. Instead, it crashes.
CREATE TABLE TableA (A TEXT, B TEXT, C TEXT);
CREATE TABLE TableB (A TEXT, B TEXT, C TEXT, PRIMARY KEY(A, B));
CREATE INDEX i on TableB (A,B,C);
INSERT INTO TableA (A, B, C) VALUES ('1', '2', '3');
INSERT INTO TableB (A, B, C) VALUES ('1', '2', '3___');
SELECT * FROM TableB WHERE A = '0'; -- works, searched key is less than the one in the table
SELECT * FROM TableB WHERE A = '1'; -- works, searched key equals the one in the table
SELECT * FROM TableB WHERE A = '2'; -- crashes, searched key is greater than the one in the table
Any of these changes to the SQL script make the crash disappear:
- Remove
TableA
and its entry - Remove the index
i
onTableB
- Remove TableB's
PRIMARY KEY(A, B)
constraint - Shorten the third value
'3___'
in TableB by at least one character. Values longer than three characters in any column seem to result in a crash. - Use a search key less than or equal to
'1'
Compiling with debugging enabled also makes the assert seen in the code snippet below fail (line ~5598):
static int
mdb_cursor_next(MDB_cursor *mc, MDB_val *key, MDB_val *data, MDB_cursor_op op)
{
MDB_page *mp;
MDB_node *leaf;
int rc;
if (mc->mc_flags & C_EOF) {
return MDB_NOTFOUND;
}
mdb_cassert(mc, mc->mc_flags & C_INITIALIZED);
mp = mc->mc_pg[mc->mc_top];
…