update version
[sqlcipher.git] / test / altercorrupt.test
blob5c50fa4a474e08564d75e39a7bce8dfb6a0066a9
1 # 2019-01-11
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
13 set testdir [file dirname $argv0]
14 source $testdir/tester.tcl
15 set testprefix altercorrupt
17 database_may_be_corrupt
19 #--------------------------------------------------------------------------
20 reset_db
21 do_test 1.0 {
22   sqlite3 db {}
23   db deserialize [decode_hexdb {
24 .open --hexdb
25 | size 24576 pagesize 4096 filename crash-685346d89b5e5f.db
26 | page 1 offset 0
27 |      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
28 |     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 06   .....@  ........
29 |     32: 00 00 63 00 00 05 f0 00 00 00 00 04 10 00 00 04   ..c.............
30 |     48: 00 00 00 00 00 00 0f f0 00 00 00 01 00 00 00 00   ................
31 |     64: 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
32 |     96: 00 00 00 00 0d 0f f8 00 05 0e cf 00 0f 79 0f d3   .............y..
33 |    112: 0f 2e 0e f3 0e cf 00 00 00 00 00 00 00 00 00 00   ................
34 |   3776: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 22   ................
35 |   3792: 05 06 17 11 11 01 31 74 61 62 6c 65 74 34 74 34   ......1tablet4t4
36 |   3808: 06 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 34   .CREATE TABLE t4
37 |   3824: 28 7a 29 39 04 06 17 11 11 01 5f 74 61 62 6c 65   (z)9......_table
38 |   3840: 74 33 74 33 05 43 52 45 41 54 45 20 54 41 42 4c   t3t3.CREATE TABL
39 |   3856: 45 20 74 33 28 78 20 49 4e 54 45 47 45 52 20 50   E t3(x INTEGER P
40 |   3872: 52 49 4d 41 52 59 20 4b 45 59 2c 20 79 29 49 03   RIMARY KEY, y)I.
41 |   3888: 06 17 11 11 01 7f 74 61 62 6c 65 74 32 74 32 04   ......tablet2t2.
42 |   3904: 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 32 28   CREATE TABLE t2(
43 |   3920: 61 2c 62 2c 63 20 50 52 49 4d 41 52 59 20 4b 45   a,b,c PRIMARY KE
44 |   3936: 59 2c 20 64 2c 20 65 2c 20 66 29 20 57 49 54 48   Y, d, e, f) WITH
45 |   3952: 4f 55 54 20 52 4f 57 49 44 58 03 07 17 11 11 01   OUT ROWIDX......
46 |   3968: 81 1b 74 61 62 6c 65 74 31 74 31 02 43 52 45 41   ..tablet1t1.CREA
47 |   3984: 54 45 20 54 41 42 4c 45 20 74 31 28 61 2c 62 2c   TE TABLE t1(a,b,
48 |   4000: 63 20 41 53 20 28 2d 62 29 20 56 49 52 54 55 41   c AS (-b) VIRTUA
49 |   4016: 4c 2c 64 20 43 48 45 43 4b 28 64 3e 35 29 2c 65   L,d CHECK(d>5),e
50 |   4032: 20 55 4e 49 51 55 45 2c 20 66 20 41 53 20 28 2b    UNIQUE, f AS (+
51 |   4048: 62 29 29 23 02 06 17 37 11 01 00 69 6e 64 65 78   b))#...7...index
52 |   4064: 73 71 6c 69 74 65 5f 61 75 74 6f 69 6e 64 65 78   sqlite_autoindex
53 |   4080: 5f 74 31 5f 31 74 31 03 00 00 00 08 00 00 00 00   _t1_1t1.........
54 | page 2 offset 4096
55 |      0: 0d 00 00 00 0a 0f 93 00 0f f6 0f eb 0f e0 0f d5   ................
56 |     16: 0f ca 0f 8f 0f b4 0f a9 0f 9e 0f 93 00 00 00 00   ................
57 |   3984: 00 00 00 09 0a 05 01 01 01 01 0a 64 6e 14 09 09   ...........dn...
58 |   4000: 05 01 01 01 01 09 5a 6d 12 09 08 05 01 01 01 01   ......Zm........
59 |   4016: 08 50 6c 10 09 07 05 01 01 01 01 07 46 6b 0e 09   .Pl.........Fk..
60 |   4032: 06 05 01 01 01 01 06 3c 6a 0c 09 05 05 01 01 01   .......<j.......
61 |   4048: 01 05 32 69 0a 09 04 05 01 01 01 01 04 28 68 08   ..2i.........(h.
62 |   4064: 09 03 05 01 01 01 01 03 1e 67 06 09 02 05 01 01   .........g......
63 |   4080: 01 01 02 14 66 04 08 01 05 09 01 01 01 0a 65 02   ....f.........e.
64 | page 3 offset 8192
65 |      0: 0a 00 00 00 0a 0f c5 00 0f fb 0f f5 0f ef 0f e9   ................
66 |     16: 0f e3 0f dd 0f d7 0f d1 0f cb 0f c5 00 00 00 00   ................
67 |   4032: 00 00 00 00 00 05 03 01 01 14 0a 05 03 01 01 12   ................
68 |   4048: 09 05 03 01 01 10 08 05 03 01 01 0e 07 05 03 01   ................
69 |   4064: 01 0c 06 05 03 01 01 0a 05 05 03 01 01 08 04 05   ................
70 |   4080: 03 01 01 06 03 05 03 01 01 04 02 04 03 01 09 02   ................
71 | page 4 offset 12288
72 |      0: 0a 00 00 00 0a 0f 75 00 0f 75 0f 83 0f 91 0f 9f   ......u..u......
73 |     16: 0f ad 0f bb 0f 00 00 00 00 00 00 00 00 00 00 00   ................
74 |   3952: 00 00 00 00 00 0d 07 01 01 01 01 01 01 9c 0a 64   ...............d
75 |   3968: 6e 14 64 0d 07 02 01 01 01 01 01 a6 09 5a 6d 12   n.d..........Zm.
76 |   3984: 5a 0d 07 01 01 01 01 01 01 b0 08 50 6c 10 50 0d   Z..........Pl.P.
77 |   4000: 07 01 01 01 01 01 01 ba 07 46 6b 0e 46 0d 07 01   .........Fk.F...
78 |   4016: 01 01 01 01 01 c4 06 3c 6a 0c 3c 0d 07 01 01 01   .......<j.<.....
79 |   4032: 01 01 01 ce 05 32 69 0a 32 0d 07 01 01 01 01 01   .....2i.2.......
80 |   4048: 01 d8 04 28 68 08 28 0d 07 01 01 01 01 01 01 e2   ...(h.(.........
81 |   4064: 03 1e 67 06 1e 0d 07 01 01 01 01 01 01 ec 02 14   ..g.............
82 |   4080: 66 04 14 0c 07 01 09 01 01 01 01 f6 0a 65 02 0a   f............e..
83 | page 5 offset 16384
84 |      0: 0d 00 00 00 03 0f e9 00 0f e9 0f fb 0f f6 00 00   ................
85 |     16: 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
86 |   4064: 00 00 00 00 00 00 00 00 00 03 ff ff ff ff ff ff   ................
87 |   4080: ff ff 9c 03 00 00 03 64 03 00 00 03 01 03 00 00   .......d........
88 | page 6 offset 20480
89 |      0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00   ................
90 | end crash-685346d89b5e5f.db
91 }]} {}
93 do_catchsql_test 1.1 {
94   ALTER TABLE t2 DROP COLUMN e;
95   ALTER TABLE t1 DROP COLUMN f;
96 } {1 {database disk image is malformed}}
99 #--------------------------------------------------------------------------
100 reset_db
101 do_test 2.0 {
102   sqlite3 db {}
103   db deserialize [decode_hexdb {
104 .open --hexdb
105 | size 24576 pagesize 4096 filename crash-0572db8f391431.db
106 | page 1 offset 0
107 |      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
108 |     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 06   .....@  ........
109 |     32: 00 00 63 00 10 05 f0 00 00 00 00 04 10 00 00 04   ..c.............
110 |     48: 00 00 00 00 00 00 0f f0 00 00 00 00 00 00 00 00   ................
111 |     96: 00 00 00 00 0d 0f f8 00 05 0e cf 00 0f 79 0f d3   .............y..
112 |    112: 0f 2e 0e f3 0e cf 00 00 00 00 00 00 00 00 00 00   ................
113 |   3776: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 22   ................
114 |   3792: 05 06 17 11 11 01 31 74 61 62 6c 65 74 34 74 34   ......1tablet4t4
115 |   3808: 06 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 34   .CREATE TABLE t4
116 |   3824: 28 7a 29 39 04 06 17 11 11 01 5f 74 61 62 6c 65   (z)9......_table
117 |   3840: 74 33 74 33 05 43 52 45 41 54 45 20 54 41 42 4c   t3t3.CREATE TABL
118 |   3856: 45 20 74 33 28 78 20 49 4e 54 55 47 45 52 20 50   E t3(x INTUGER P
119 |   3872: 52 49 4d 41 52 59 20 4b 45 59 2c 20 79 29 49 03   RIMARY KEY, y)I.
120 |   3888: 06 17 11 11 01 7f 74 61 62 6c 65 74 32 74 32 04   ......tablet2t2.
121 |   3904: 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 32 28   CREATE TABLE t2(
122 |   3920: 61 2c 62 2c 63 20 50 52 49 4d 41 52 59 20 4b 45   a,b,c PRIMARY KE
123 |   3936: 59 2c 20 64 2c 20 65 2c 20 66 29 20 57 49 54 48   Y, d, e, f) WITH
124 |   3952: 4f 55 54 20 52 4f 57 49 44 58 05 07 17 11 11 01   OUT ROWIDX......
125 |   3968: 81 1b 74 61 62 6c 65 74 31 74 31 02 43 52 45 41   ..tablet1t1.CREA
126 |   3984: 54 45 20 54 41 42 4c 45 20 74 31 28 61 2c 62 2c   TE TABLE t1(a,b,
127 |   4000: 63 20 41 53 20 28 2d 62 29 20 56 49 52 54 55 41   c AS (-b) VIRTUA
128 |   4016: 4c 2c 64 20 43 48 45 43 4b 28 64 3e 35 29 2c 65   L,d CHECK(d>5),e
129 |   4032: 20 55 4e 49 51 55 45 2c 20 66 20 41 53 20 28 2b    UNIQUE, f AS (+
130 |   4048: 62 29 29 23 02 06 17 37 11 01 00 69 6e 64 65 78   b))#...7...index
131 |   4064: 73 71 6c 69 74 65 5f 61 75 74 6f 69 6e 64 65 78   sqlite_autoindex
132 |   4080: 5f 74 31 5f 31 84 31 03 01 00 00 08 00 00 00 00   _t1_1.1.........
133 | page 2 offset 4096
134 |      0: 0d 00 00 00 0a 0f 93 00 0f f6 0f eb 0f e0 0f d5   ................
135 |     16: 0f ca 0f 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
136 |   3984: 00 00 00 09 0a 05 01 01 01 01 0a 64 6e 14 09 09   ...........dn...
137 |   4000: 05 01 01 01 01 09 5a 6d 12 09 08 05 01 00 f1 01   ......Zm........
138 |   4016: 08 50 6c 10 09 07 05 01 01 01 01 07 46 6b 0e 09   .Pl.........Fk..
139 |   4032: 06 05 01 00 f1 01 06 3c 6a 0c 09 05 05 01 01 01   .......<j.......
140 |   4048: 01 05 32 69 0a 09 04 05 01 01 01 01 04 28 68 08   ..2i.........(h.
141 |   4064: 57 03 05 01 01 01 01 03 1e 67 06 09 02 05 01 01   W........g......
142 |   4080: 01 01 02 14 66 04 08 01 05 09 01 01 01 0a 65 02   ....f.........e.
143 | page 3 offset 8192
144 |      0: 09 ff ff ff fa 0f c5 00 0f fb 0f f5 0f ef 0f e9   ................
145 |     16: 0f e3 0f dd 0f d7 00 00 00 00 00 00 00 00 00 00   ................
146 |   4032: 00 00 00 00 00 05 03 01 01 14 0a 05 03 01 01 12   ................
147 |   4048: 09 05 03 01 01 10 08 05 03 01 01 0e 07 05 03 01   ................
148 |   4064: 01 0c 06 05 03 01 01 0a 05 05 03 01 01 08 04 05   ................
149 |   4080: 03 01 01 06 03 05 03 01 01 04 02 04 03 01 09 02   ................
150 | page 4 offset 12288
151 |      0: 0a 00 00 00 0a 0f 75 00 0f 75 0f 83 0f 91 0f 9f   ......u..u......
152 |     16: 0f ad 0f bb 0f 00 00 00 00 00 01 00 00 00 00 00   ................
153 |   3952: 00 00 00 00 00 0d 07 01 01 01 01 01 01 9c 0a 64   ...............d
154 |   3968: 6e 14 64 0d 07 02 01 01 01 01 01 a6 09 5a 6d 12   n.d..........Zm.
155 |   3984: 5a 0d 07 01 01 01 01 d4 01 b0 08 50 6c 10 50 0d   Z..........Pl.P.
156 |   4000: 07 01 01 01 01 01 01 ba 07 46 6b 0e 46 0d 07 00   .........Fk.F...
157 |   4016: 01 01 01 01 01 c4 06 3c 6a 0c 3c 0d 07 01 01 01   .......<j.<.....
158 |   4032: 01 01 01 ce 05 32 69 0a 32 0d 07 01 01 01 01 01   .....2i.2.......
159 |   4048: 01 d8 04 28 68 08 28 0d 07 01 01 01 01 01 01 e2   ...(h.(.........
160 |   4064: 03 1e 67 06 1e 0d 07 01 01 01 01 01 01 ec 02 14   ..g.............
161 |   4080: 66 04 14 0c 07 01 09 01 01 00 f1 f6 0a 65 02 0a   f............e..
162 | page 5 offset 16384
163 |      0: 0d 00 00 00 03 0f e9 00 0f e9 0f fb 0f f6 00 00   ................
164 |   4064: 00 00 00 00 00 00 00 00 00 03 ff ff ff ff ff ff   ................
165 |   4080: ff ff 9c 03 00 00 03 64 03 00 01 03 01 03 00 00   .......d........
166 | page 6 offset 20480
167 |      0: 0d 00 10 00 00 10 01 00 00 00 00 00 00 00 00 00   ................
168 | end crash-0572db8f391431.db
169 }]} {}
171 do_catchsql_test 2.1 {
172   ALTER TABLE t1 DROP COLUMN a;
173 } {1 {database disk image is malformed}}
175 finish_test