SQLite Forum

Possible faulty assertion in JSON1 extension

Possible faulty assertion in JSON1 extension

(1) By nalgeon on 2021-12-20 21:32:10 [source]

Steps to reproduce (Ubuntu 20.04.1 LTS):

  1. Download json1.c as of trunk.

  2. Compile as a separate extension

gcc -fPIC -shared json1.c -o json1.so
  1. Load in CLI and execute a query
sqlite> .load ./json1
sqlite> select json('{"answer" : 42}');


sqlite3: json1.c:503: jsonRenderNode: Assertion `pNode->eU==1' failed.
Aborted (core dumped)

Reproduces on 3.37. Does not reproduce on 3.36

Seems like the change was introduced in check-in 7b8ea2298927fd34. It was later partially rolled back by e162da3ab4c183b6 and 0e0c23fcc493a5d6, but the line 503 remains as of 7b8ea2298927fd34.

(2.1) By Richard Hipp (drh) on 2021-12-21 10:53:28 edited from 2.0 in reply to 1 [link] [source]

Thanks for the report. The fix is in check-in d9f814a6402ca7fd. Your workaround for version 3.37.0 is to compile using:

gcc -fPIC -shared -DNDEBUG json1.c -o json1.so

In other words, add the -DNDEBUG flag to the compile command-line.

It turns out that the json1.c module requires that either SQLITE_DEBUG or NDEBUG be defined. If neither is defined, bad things happen, as you discovered. When json1.c is compile as part of the SQLite amalgamation (which is the only way we test it, actually), the SQLITE_DEBUG and NDEBUG macros are set up automatically. So this is never an issue when using the built-in json1.c. The fix in check-in d9f814a6402ca7fd is to add an #ifdef and a #define to ensure that either SQLITE_DEBUG or NDEBUG is defined when json1.c is not part of the amalgamation.

(3) By nalgeon on 2021-12-21 02:43:48 in reply to 2.0 [link] [source]

Thanks for the fix and the workaround!