1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Ensure that "PRAGMA integrity_check" reports an error if the free-list count header field contains a value smaller than the actual number of pages on the database free-list.

FossilOrigin-Name: 26f64986d1ed59c554a7cb9e00e86a7f148f1fc6
This commit is contained in:
dan
2015-09-18 14:45:01 +00:00
parent 3a84411fc4
commit ad41f5eda3
4 changed files with 61 additions and 9 deletions

View File

@ -17,6 +17,7 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix corrupt2
# Do not use a codec for tests in this file, as the database file is
# manipulated directly using tcl scripts (using the [hexio_write] command).
@ -558,4 +559,51 @@ ifcapable autovacuum {
}
}
#-------------------------------------------------------------------------
# Test that PRAGMA integrity_check detects cases where the freelist-count
# header field is smaller than the actual number of pages on the freelist.
#
reset_db
do_execsql_test 14.0 {
PRAGMA auto_vacuum = 0;
CREATE TABLE t1(x);
INSERT INTO t1 VALUES(randomblob(3500));
DELETE FROM t1;
}
do_execsql_test 14.1 {
PRAGMA integrity_check;
PRAGMA freelist_count;
} {ok 3}
# There are now 3 free pages. Modify the header-field so that it
# (incorrectly) says that just 2 are free.
do_test 14.2 {
db close
hexio_write test.db 36 [hexio_render_int32 2]
sqlite3 db test.db
execsql { PRAGMA freelist_count }
} {2}
do_execsql_test 14.3 {
PRAGMA integrity_check;
} {{*** in database main ***
Main freelist: free-page count in header is too small}}
# Use 2 of the free pages on the free-list.
#
do_execsql_test 14.4 {
INSERT INTO t1 VALUES(randomblob(2500));
PRAGMA freelist_count;
} {0}
do_execsql_test 14.5 {
PRAGMA integrity_check;
} {{*** in database main ***
Page 3 is never used}}
finish_test
finish_test