SQLite User Forum

A testcase causing Assertion `p->pRight==0' failed
Login

A testcase causing Assertion `p->pRight==0' failed

(1) By Jingzhou Fu (fuboat) on 2022-03-07 13:52:02 [source]

System Information:

compile-time options: CC=clang-12 ./configure --enable-debug
sqlite_source_id: 2022-03-07 01:29:36 0057bbb508e7662b0da19e981c07ef10236cb616bda952745de3aa2d1c286289
output: sqlite3: sqlite3.c:104005: dupedExprStructSize: Assertion `p->pRight==0' failed.

PoC:

CREATE TABLE t4(x, y, z);
CREATE TRIGGER ttt AFTER INSERT ON t4 WHEN new.y<0 BEGIN
    SELECT x, y, z FROM t4;
    DELETE FROM t4 WHERE y=32;
    UPDATE t4 SET x=y+1, y=0 WHERE y=32;
    INSERT INTO t4(x, y, z) 
    SELECT e_master LIMIT 1,#1;

It is obvious that the testcase contains syntax error. When compiled with release mode, the output changes to:

Parse error near line 2: near "#1": syntax error
  ERT INTO t4(x, y, z)      SELECT e_master LIMIT 1,#1;
                                      error here ---^

(2) By Richard Hipp (drh) on 2022-03-07 16:27:07 in reply to 1 [link] [source]

Simplified test case:

CREATE TABLE t1(a INT);
CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN
  INSERT INTO t1 SELECT b LIMIT 1,#2;
END;

You are correct - this is completely harmless for release builds. The assertion fault indicates that an internal invariant associated with expression trees has been violated in a statement that contains a syntax error. Because the syntax error will (eventually) cause the stack to unwind, the fault is harmless.

A fix is check-in 5e0ed49b3d739d29.