xref: /sqlite-3.40.0/test/corruptA.test (revision f2fcd075)
1# 2008 July 11
2#
3# The author disclaims copyright to this source code.  In place of
4# 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# This file implements regression tests for SQLite library.
12#
13# This file implements tests to make sure SQLite does not crash or
14# segfault if it sees a corrupt database file.  It specifically focuses
15# on corrupt database headers.
16#
17# $Id: corruptA.test,v 1.1 2008/07/11 16:39:23 drh Exp $
18
19set testdir [file dirname $argv0]
20source $testdir/tester.tcl
21
22
23# Create a database to work with.
24#
25do_test corruptA-1.1 {
26  execsql {
27    CREATE TABLE t1(x);
28    INSERT INTO t1(x) VALUES(1);
29  }
30  expr {[file size test.db]>=1024}
31} {1}
32integrity_check corruptA-1.2
33
34# Corrupt the file header in various ways and make sure the corruption
35# is detected when opening the database file.
36#
37db close
38file copy -force test.db test.db-template
39
40set unreadable_version 02
41ifcapable wal { set unreadable_version 03 }
42do_test corruptA-2.1 {
43  file copy -force test.db-template test.db
44  hexio_write test.db 19 $unreadable_version   ;# the read format number
45  sqlite3 db test.db
46  catchsql {SELECT * FROM t1}
47} {1 {file is encrypted or is not a database}}
48
49do_test corruptA-2.2 {
50  db close
51  file copy -force test.db-template test.db
52  hexio_write test.db 21 41   ;# max embedded payload fraction
53  sqlite3 db test.db
54  catchsql {SELECT * FROM t1}
55} {1 {file is encrypted or is not a database}}
56
57do_test corruptA-2.3 {
58  db close
59  file copy -force test.db-template test.db
60  hexio_write test.db 22 1f   ;# min embedded payload fraction
61  sqlite3 db test.db
62  catchsql {SELECT * FROM t1}
63} {1 {file is encrypted or is not a database}}
64
65do_test corruptA-2.4 {
66  db close
67  file copy -force test.db-template test.db
68  hexio_write test.db 23 21   ;# min leaf payload fraction
69  sqlite3 db test.db
70  catchsql {SELECT * FROM t1}
71} {1 {file is encrypted or is not a database}}
72
73
74finish_test
75