AryaWu/sqlite
0
1# 2015-03-302#3# The author disclaims copyright to this source code. In place of4# a legal notice, here is a blessing:5#6# May you do good and not evil.7# May you find forgiveness for yourself and forgive others.8# May you share freely, never taking more than you give.9#10#***********************************************************************11#12# Corruption consisting of a database page that thinks it is a child13# of itself.14#15 16set testdir [file dirname $argv0]17source $testdir/tester.tcl18set testprefix corruptJ19 20if {[permutation]=="mmap"} {21 finish_test22 return23}24 25# This module uses hard-coded offsets which do not work if the reserved_bytes26# value is nonzero.27if {[nonzero_reserved_bytes]} {finish_test; return;}28 29database_may_be_corrupt30 31# Initialize the database.32#33do_execsql_test 1.1 {34 PRAGMA page_size=1024;35 PRAGMA auto_vacuum=0;36 CREATE TABLE t1(a,b);37 WITH RECURSIVE c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<10)38 INSERT INTO t1(a,b) SELECT i, zeroblob(700) FROM c;39} {}40db close41 42# Corrupt the root page of the t1 table such that the left-child pointer43# for the very first cell points back to the root. Then try to DROP the44# table. The clearDatabasePage() routine should not loop.45#46do_test 1.2 {47 hexio_write test.db [expr {2*1024-2}] 0248 sqlite3 db test.db49 catchsql { DROP TABLE t1 }50} {1 {database disk image is malformed}}51 52# Similar test using a WITHOUT ROWID table53#54do_test 2.1 {55 db close56 forcedelete test.db57 sqlite3 db test.db58 db eval {59 PRAGMA page_size=1024;60 PRAGMA auto_vacuum=0;61 CREATE TABLE t1(a,b,PRIMARY KEY(a,b)) WITHOUT ROWID;62 WITH RECURSIVE c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<100)63 INSERT INTO t1(a,b) SELECT i, zeroblob(200) FROM c;64 }65} {}66 67# The table is three levels deep. Corrupt the left child of an intermediate68# page so that it points back to the root page.69#70do_test 2.2 {71 db close72 hexio_read test.db [expr {9*1024+391}] 873} {00000008814D0401}74do_test 2.2b {75 hexio_write test.db [expr {9*1024+391}] 0000000276 sqlite3 db test.db77 catchsql { PRAGMA secure_delete=ON; DROP TABLE t1; }78} {1 {database disk image is malformed}}79 80finish_test81 