I am getting an access violation in rtree.c::nodeGetRowid() using a
database image of questionable integrity (the application the database
was last updated on shut down abnormally, but executing PRAGMA
integrity_check returns "ok" and there is no journal file).  The
access violation can be reproduced by executing the following query in
the sqlite3 shell:

DELETE FROM history_rtree WHERE NOT EXISTS(SELECT _id FROM history
WHERE history._id = history_rtree._id);

Using http://sqlite.org/sqlite-source-3_6_23_1.zip (to get reasonable
line numbers), the call stack is roughly:
>       sqlite.exe!nodeGetRowid(Rtree * pRtree=0x00348340, RtreeNode * 
> pNode=0x00000000, int iCell=0x00000000)  Line 568 + 0x3 bytes    C
        sqlite.exe!nodeRowidIndex(Rtree * pRtree=0x00348340, RtreeNode *
pNode=0x00000000, __int64 iRowid=0x000000000000002d)  Line 874 + 0x23
bytes   C
        sqlite.exe!rtreeUpdate(sqlite3_vtab * pVtab=0x00348340, int
nData=0x00000001, Mem * * azData=0x0034f908, __int64 *
pRowid=0x0012f100)  Line 2385 + 0x41 bytes      C
        sqlite.exe!sqlite3VdbeExec(Vdbe * p=0x00348ff0)  Line 6125 + 0x29 bytes 
C
        sqlite.exe!sqlite3Step(Vdbe * p=0x00348ff0)  Line 370 + 0x9 bytes       
C
        sqlite.exe!sqlite3_step(sqlite3_stmt * pStmt=0x00348ff0)  Line 432 +
0x9 bytes       C
        sqlite.exe!shell_exec(sqlite3 * db=0x00343210, const char *
zSql=0x0052dcc0, int (void *, int, char * *, char * *, int *)*
xCallback=0x00456400, callback_data * pArg=0x0012f940, char * *
pzErrMsg=0x0012f7b4)  Line 1012 + 0x9 bytes     C

The call to findLeafNode() at rtree.c line 2379 returned SQLITE_OK but
set pLeaf to NULL, and I note that this postcondition is documented as
possible.

Adding a check for pLeaf to the if condition on line 2383 prevents the
access violation:

if( rc==SQLITE_OK && pLeaf ) {

Is this the correct fix?

Thanks,
Peter Kolbus
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to