SQLite

Check-in [f221f31eff]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add test case for the obscure corruption detection added by the previous commit.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f221f31efff83651b9af295b98cfe98bcba3ad54
User & Date: dan 2009-12-05 18:16:11.000
References
2009-12-05
18:34
Fix to check-in [f221f31eff]: Make sure local variable rc is declared even when compiled without SQLITE_DEBUG. (check-in: 7a9a35327c user: drh tags: trunk)
Context
2009-12-05
18:34
Fix to check-in [f221f31eff]: Make sure local variable rc is declared even when compiled without SQLITE_DEBUG. (check-in: 7a9a35327c user: drh tags: trunk)
18:16
Add test case for the obscure corruption detection added by the previous commit. (check-in: f221f31eff user: dan tags: trunk)
18:03
Catch an obscure case of database corruption. (check-in: 0f9b17a6da user: dan tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to test/corrupt.test.
252
253
254
255
256
257
258






















































259
260

  set offset [expr ($rootpage * 1024)-14+2]
  hexio_write test.db $offset 00FF
  sqlite3 db test.db 

  catchsql { INSERT INTO t1 VALUES( randomblob(10) ) }
} {1 {database disk image is malformed}}























































finish_test







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314

  set offset [expr ($rootpage * 1024)-14+2]
  hexio_write test.db $offset 00FF
  sqlite3 db test.db 

  catchsql { INSERT INTO t1 VALUES( randomblob(10) ) }
} {1 {database disk image is malformed}}

ifcapable oversize_cell_check {
  db close
  file delete -force test.db test.db-journal
  sqlite3 db test.db
  execsql { 
    PRAGMA page_size = 1024; CREATE TABLE t1(x);
  }

  do_test corrupt-7.1 {
    for {set i 0} {$i < 39} {incr i} {
      execsql {
        INSERT INTO t1 VALUES(X'000100020003000400050006000700080009000A');
      }
    }
  } {}
  db close
  
  # Corrupt the root page of table t1 so that the first offset in the 
  # cell-offset array points to the data for the SQL blob associated with
  # record (rowid=10). The root page still passes the checks in btreeInitPage(),
  # because the start of said blob looks like the start of a legitimate 
  # page cell.
  #
  # Test case cc-2 overwrites the blob so that it no longer looks like a
  # real cell. But, by the time it is overwritten, btreeInitPage() has already
  # initialized the root page, so no corruption is detected.
  #
  # Test case cc-3 inserts an extra record into t1, forcing balance-deeper
  # to run. After copying the contents of the root page to the new child,
  # btreeInitPage() is called on the child. This time, it detects corruption
  # (because the start of the blob associated with the (rowid=10) record
  # no longer looks like a real cell). At one point the code assumed that 
  # detecting corruption was not possible at that point, and an assert() failed.
  #
  set fd [open test.db r+]
  fconfigure $fd -translation binary -encoding binary
  seek $fd [expr 1024+8]
  puts -nonewline $fd "\x03\x14"
  close $fd
  
  sqlite3 db test.db
  do_test corrupt-7.2 {
    execsql { 
      UPDATE t1 SET x = X'870400020003000400050006000700080009000A' 
      WHERE rowid = 10;
    }
  } {}
  do_test corrupt-7.3 {
    catchsql {
      INSERT INTO t1 VALUES(X'000100020003000400050006000700080009000A');
    }
  } {1 {database disk image is malformed}}
}

finish_test
Changes to test/fts3rnd.test.
214
215
216
217
218
219
220
221
222
223
224
225
226
      set nNear 11
      set match [join $terms " NEAR/$nNear "]
      set fts3 [execsql { SELECT docid FROM t1 WHERE t1 MATCH $match }]
      set tcl [simple_near $terms $nNear]
      do_test fts3rnd-1.$nodesize.$iTest.5.$i.$match {
        execsql { SELECT docid FROM t1 WHERE t1 MATCH $match }
      } [simple_near $terms $nNear]
if {$::nErr} {exit -1}
    }
  }
}

finish_test







<





214
215
216
217
218
219
220

221
222
223
224
225
      set nNear 11
      set match [join $terms " NEAR/$nNear "]
      set fts3 [execsql { SELECT docid FROM t1 WHERE t1 MATCH $match }]
      set tcl [simple_near $terms $nNear]
      do_test fts3rnd-1.$nodesize.$iTest.5.$i.$match {
        execsql { SELECT docid FROM t1 WHERE t1 MATCH $match }
      } [simple_near $terms $nNear]

    }
  }
}

finish_test