The problem occurs because the INSERT operation leaves its cursor open, though
marked CURSOR_INVALID, while holding a reference to a second-level page of the
btree. When the trigger fires it deletes content out from under this cursor,
which is normally OK since the cursor is invalid. However, during the second
INSERT inside the trigger, when a page is removed from the freelist to hold
the new content, that page is checked to make sure it is unreferenced. This
check fails since the invalid INSERT cursor is still holding a reference to
the page. That reference makes it appear as if the page was on the freelist
and in a btree at the same time and so an SQLITE_CORRUPT error is thrown.
However, the page is not really on the btree since the cursor that is
referencing it is marked CURSOR_INVALID.

This problem has existing in the code since late 2009. It is very difficult
to hit, however (which helps to explain why it has gone undetected until now).
The problem is very sensitive to the specific constants used in the script
shown above.

This page was generated in about
0.017s by
Fossil version 2.4 [0b4c3f5a28] 2017-09-26 20:41:54