sqlite3.8.7 crashes when creating an index with WAL mode disabled

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

sqlite3.8.7 crashes when creating an index with WAL mode disabled

RP McMurphy
Consider the following build cmd line:

        gcc -o sqlite3.exe -DSQLITE_OMIT_WAL sqlite3.c shell.c

The build succeeds when using MinGW on Windows.

Now start the built exe with a memory database:

        sqlite3 :memory:

And execute the following query:

        create table v(y);
        with recursive cnt(x) as (select 1 union all select x+1 from cnt limit 100000)
        insert into v select * from cnt;
        create index w on v(y);

And watch as it crashes when creating the index.

I tracked the problem down to the following missing library bindings:

        CreateFileMappingA
        CreateFileMappingW
        MapViewOfFile
        UnmapViewOfFile

All four of those library bindings are disabled by the existence of SQLITE_OMIT_WAL. sqlite tries to execute code at address 0 when the table to larger than some value. If I use 96255 instead of 100000 in the above query there is no crash. And increasing by one to 96256 the crash occurs.

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

Re: sqlite3.8.7 crashes when creating an index with WAL mode disabled

Simon Davies
On 4 November 2014 04:17, RP McMurphy <[hidden email]> wrote:

> Consider the following build cmd line:
>
>         gcc -o sqlite3.exe -DSQLITE_OMIT_WAL sqlite3.c shell.c
>
> The build succeeds when using MinGW on Windows.
>
> Now start the built exe with a memory database:
>
>         sqlite3 :memory:
>
> And execute the following query:
>
>         create table v(y);
>         with recursive cnt(x) as (select 1 union all select x+1 from cnt limit 100000)
>         insert into v select * from cnt;
>         create index w on v(y);
>
> And watch as it crashes when creating the index.

From https://www.sqlite.org/compile.html:

Important Note: The SQLITE_OMIT_* options do not work with the
amalgamation or with pre-packaged C code files. SQLITE_OMIT_*
compile-time options only work correctly when SQLite is built from
canonical source files.

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

Re: sqlite3.8.7 crashes when creating an index with WAL mode disabled

James K. Lowden
On Tue, 4 Nov 2014 12:06:35 +0000
Simon Davies <[hidden email]> wrote:

> > And watch as it crashes when creating the index.
>
> From https://www.sqlite.org/compile.html:
>
> Important Note: The SQLITE_OMIT_* options do not work with the
> amalgamation or with pre-packaged C code files. SQLITE_OMIT_*
> compile-time options only work correctly when SQLite is built from
> canonical source files.

Perhaps this could be caught at compile time.  The process that creates
the amalgamation could add a preprocessor macro defining e.g.
_SQLITE_AMALGAMATION_.  The SQLITE_OMIT_* macros could test for that
definition and #pragma error if found.  

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

Re: sqlite3.8.7 crashes when creating an index with WAL mode disabled

RP McMurphy
In reply to this post by RP McMurphy

>Perhaps this could be caught at compile time.  The process that creates
>the amalgamation could add a preprocessor macro defining e.g.
>_SQLITE_AMALGAMATION_.  The SQLITE_OMIT_* macros could test for that
>definition and #pragma error if found.  

I think there is a much easier solution. Since those four API bindings are needed by more than just the WAL code then simply remove the four checks and have the APIs always bind.

This appears to be a simple oversight about the usage of the APIs. They are used by code other than WAL. Specifically the indexing code also uses the file mapping APIs.

RP
_______________________________________________
sqlite-users mailing list
[hidden email]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users