Table-valued function crashing in SQLite 3.20

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Table-valued function crashing in SQLite 3.20

Jens Alfke-2
We have a virtual table serving as a table-valued function, which has worked fine up through SQLite 3.19, but now in 3.20.1 is crashing whenever it’s used. I know there were changes in 3.20 relating to native functions taking pointers, but this doesn’t seem to be related to that. Were there any other possibly-breaking changes to the way virtual tables work? I didn’t see any in the release notes.

As virtual tables go it’s pretty simple. It was shamelessly copied from the json_each implementation in json1.c, then adapted from there, and it’s still quite similar (it’s just that the data collection it’s iterating over is not in JSON format.)

What I’m seeing is that our fl_each's  xConnect and xBestIndex are called at compile/prepare time, then xOpen is called during the first call to sqlite3_step, and immediately after that comes a crash in sqlite3VdbeCursorMoveto() because the passed-in VdbeCursor is NULL. (Actually pp is a valid pointer, but *pp is NULL.) This is right at the start of handling the next opcode, Column.

Top of the backtrace is:
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: sqlite3VdbeCursorMoveto(pp=0x00007ffeefbfb028, piCol=0x00007ffeefbfb034) at sqlite3.c:75132
  * frame #1: sqlite3VdbeExec(p=0x0000000101171680) at sqlite3.c:81369
    frame #2: sqlite3Step(p=0x0000000101171680) at sqlite3.c:77352
    frame #3: sqlite3_step(pStmt=0x0000000101171680) at sqlite3.c:77416

The SQL query looks like:
        SELECT sequence, key, version, flags
        FROM kv_default
        WHERE (EXISTS (SELECT 1 FROM fl_each(body, 'likes') AS _like WHERE _like.value = 'climbing’))

EXPLAIN returns:
        0 Init 0 24 0 00 Start at 24
        1 Integer 0 2 0 00 r[2]=0; Init EXISTS result
        2 Integer 1 3 0 00 r[3]=1; LIMIT counter
        3 VOpen 1 0 0 vtab:10116FC00 00
        4 Column 0 4 6 00 r[6]=kv_default.body <==CRASH AT THIS OPCODE
        5 String8 0 7 0 likes 00 r[7]='likes'
        6 Integer 2 4 0 00 r[4]=2
        7 Integer 2 5 0 00 r[5]=2
        8 VFilter 1 14 4 00 iplan=r[4] zplan=''
        9 VColumn 1 1 8 00 r[8]=vcolumn(1); fl_each.value
        10 Ne 9 13 8 (BINARY) 51 if r[8]!=r[9] goto 13
        11 Integer 1 2 0 00 r[2]=1
        12 DecrJumpZero 3 14 0 00 if (--r[3])==0 goto 14
        13 VNext 1 9 0 00
        14 IfNot 2 23 1 00
        15 OpenRead 0 4 0 5 00 root=4 iDb=0; kv_default
        16 Rewind 0 23 0 00
        17 Column 0 1 11 00 r[11]=kv_default.sequence
        18 Column 0 0 12 00 r[12]=kv_default.key
        19 Column 0 3 13 00 r[13]=kv_default.version
        20 Column 0 2 14 0 00 r[14]=kv_default.flags
        21 ResultRow 11 4 0 00 output=r[11..14]
        22 Next 0 17 0 01
        23 Halt 0 0 0 00
        24 Transaction 0 0 4 0 01 usesStmtJournal=0
        25 String8 0 9 0 climbing 00 r[9]='climbing'
        26 Goto 0 1 0 00

(This is on Mac OS; I’m on the current beta of 10.13, though that shouldn’t make a difference.)

—Jens
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Table-valued function crashing in SQLite 3.20

Jens Alfke-2
For what it’s worth, the instructions generated in 3.19.2 (which don't crash) are slightly different: the OpenRead and Rewind instructions are at the top, not down at location 15 —

        0 Init 0 24 0 00 Start at 24
        1 OpenRead 0 4 0 5 00 root=4 iDb=0; kv_default
        2 Rewind 0 23 0 00
        3 Integer 0 2 0 00 r[2]=0; Init EXISTS result
        4 Integer 1 3 0 00 r[3]=1; LIMIT counter
        5 VOpen 1 0 0 vtab:10128F730 00
        6 Column 0 4 6 00 r[6]=kv_default.body
        7 String8 0 7 0 likes 00 r[7]='likes'
        8 Integer 2 4 0 00 r[4]=2
        9 Integer 2 5 0 00 r[5]=2
        10 VFilter 1 16 4 00 iplan=r[4] zplan=''
        11 VColumn 1 1 8 00 r[8]=vcolumn(1); fl_each.value
        12 Ne 9 15 8 (BINARY) 51 if r[8]!=r[9] goto 15
        13 Integer 1 2 0 00 r[2]=1
        14 DecrJumpZero 3 16 0 00 if (--r[3])==0 goto 16
        15 VNext 1 11 0 00
        16 IfNot 2 22 1 00
        17 Column 0 1 11 00 r[11]=kv_default.sequence
        18 Column 0 0 12 00 r[12]=kv_default.key
        19 Column 0 3 13 00 r[13]=kv_default.version
        20 Column 0 2 14 0 00 r[14]=kv_default.flags
        21 ResultRow 11 4 0 00 output=r[11..14]
        22 Next 0 3 0 01
        23 Halt 0 0 0 00
        24 Transaction 0 0 4 0 01 usesStmtJournal=0
        25 String8 0 9 0 climbing 00 r[9]='climbing'
        26 Goto 0 1 0 00
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Table-valued function crashing in SQLite 3.20

Richard Hipp-3
In reply to this post by Jens Alfke-2
On 9/11/17, Jens Alfke <[hidden email]> wrote:
> We have a virtual table serving as a table-valued function, which has worked
> fine up through SQLite 3.19, but now in 3.20.1 is crashing whenever it’s
> used.

Does it work on trunk?


--
D. Richard Hipp
[hidden email]
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Table-valued function crashing in SQLite 3.20

Jens Alfke-2


> On Sep 11, 2017, at 4:20 PM, Richard Hipp <[hidden email]> wrote:
>
> Does it work on trunk?

I downloaded "sqlite-snapshot-201708251543.tar.gz”, used the included sqlite3.{c,h}, and got exactly the same crash.

—Jens
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Table-valued function crashing in SQLite 3.20

Richard Hipp-3
On 9/12/17, Jens Alfke <[hidden email]> wrote:
>
>
>> On Sep 11, 2017, at 4:20 PM, Richard Hipp <[hidden email]> wrote:
>>
>> Does it work on trunk?
>
> I downloaded "sqlite-snapshot-201708251543.tar.gz”, used the included
> sqlite3.{c,h}, and got exactly the same crash.
>

The proposed fix for your problem is from 20170904 -
https://www.sqlite.org/src/info/c7f9f47b239fdd99

I have uploaded a new snapshot for you.

--
D. Richard Hipp
[hidden email]
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Table-valued function crashing in SQLite 3.20

Jens Alfke-2


> On Sep 12, 2017, at 10:50 AM, Richard Hipp <[hidden email]> wrote:
>
> The proposed fix for your problem is from 20170904 -
> https://www.sqlite.org/src/info/c7f9f47b239fdd99 <https://www.sqlite.org/src/info/c7f9f47b239fdd99>
>
> I have uploaded a new snapshot for you.

Thanks, this does look like exactly the same bug.
But the latest snapshot at http://www.sqlite.org/download.html <http://www.sqlite.org/download.html> is still the 201708251543 one. Did you upload the new one somewhere else?

—Jens
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Table-valued function crashing in SQLite 3.20

Jens Alfke-2


> On Sep 12, 2017, at 1:00 PM, Jens Alfke <[hidden email]> wrote:
>
> Thanks, this does look like exactly the same bug.
> But the latest snapshot at http://www.sqlite.org/download.html <http://www.sqlite.org/download.html> <http://www.sqlite.org/download.html <http://www.sqlite.org/download.html>> is still the 201708251543 one. Did you upload the new one somewhere else?

The new snapshot is visible to me now, and I can confirm that it fixes the crash. Thanks!

—Jens
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Table-valued function crashing in SQLite 3.20

raypoker79
In reply to this post by Jens Alfke-2
This is a scam and has been reported to attorney General and will be filing complaint with bbb,,I did not request this and habe cancelled all cards 


Sent via the Samsung Galaxy S7, an AT&T 4G LTE smartphone
-------- Original message --------From: Jens Alfke <[hidden email]> Date: 9/12/17  5:31 PM  (GMT-05:00) To: SQLite mailing list <[hidden email]> Subject: Re: [sqlite] Table-valued function crashing in SQLite 3.20


> On Sep 12, 2017, at 1:00 PM, Jens Alfke <[hidden email]> wrote:
>
> Thanks, this does look like exactly the same bug.
> But the latest snapshot at http://www.sqlite.org/download.html <http://www.sqlite.org/download.html> <http://www.sqlite.org/download.html <http://www.sqlite.org/download.html>> is still the 201708251543 one. Did you upload the new one somewhere else?

The new snapshot is visible to me now, and I can confirm that it fixes the crash. Thanks!

—Jens
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users