SQLite

Check-in [2dcd5287a0]
Login

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

Overview
Comment:Fix a problem in shared_err.test preventing it from running properly and add a test to corrupt2.test to cover another corruption detection case. (CVS 5355)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2dcd5287a0d71140baa23aae2ab3d95d78a5676d
User & Date: danielk1977 2008-07-07 17:55:29.000
Context
2008-07-07
18:42
Fix an error introduced by (5346). The list could become corrupted when the database was truncated. (CVS 5356) (check-in: fbd320ed27 user: danielk1977 tags: trunk)
17:55
Fix a problem in shared_err.test preventing it from running properly and add a test to corrupt2.test to cover another corruption detection case. (CVS 5355) (check-in: 2dcd5287a0 user: danielk1977 tags: trunk)
17:53
When sqlite3_create_collation is called with an invalid encoding, return SQLITE_MISUSE. (CVS 5354) (check-in: eae4105d8a user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to test/corrupt2.test.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests to make sure SQLite does not crash or
# segfault if it sees a corrupt database file.
#
# $Id: corrupt2.test,v 1.7 2008/07/07 17:04:23 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# The following tests - corrupt2-1.* - create some databases corrupted in
# specific ways and ensure that SQLite detects them as corrupt.
#







|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests to make sure SQLite does not crash or
# segfault if it sees a corrupt database file.
#
# $Id: corrupt2.test,v 1.8 2008/07/07 17:55:29 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# The following tests - corrupt2-1.* - create some databases corrupted in
# specific ways and ensure that SQLite detects them as corrupt.
#
164
165
166
167
168
169
170






171
172
173
174
175
176
177
  seek $fd [expr 1024*3 + $iCelloffset]
  puts -nonewline $fd "\00\00\00\00" 
  close $fd

  sqlite3 db2 corrupt.db 
  catchsql {
    DROP TABLE t1;






  } db2
} {1 {database disk image is malformed}}

do_test corrupt2-4.1 {
  file delete -force corrupt.db
  file delete -force corrupt.db-journal
  sqlite3 db2 corrupt.db 







>
>
>
>
>
>







164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
  seek $fd [expr 1024*3 + $iCelloffset]
  puts -nonewline $fd "\00\00\00\00" 
  close $fd

  sqlite3 db2 corrupt.db 
  catchsql {
    DROP TABLE t1;
  } db2
} {1 {database disk image is malformed}}

do_test corrupt2-4.1 {
  catchsql {
    SELECT * FROM t2;
  } db2
} {1 {database disk image is malformed}}

do_test corrupt2-4.1 {
  file delete -force corrupt.db
  file delete -force corrupt.db-journal
  sqlite3 db2 corrupt.db 
Changes to test/shared_err.test.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
#***********************************************************************
#
# The focus of the tests in this file are IO errors that occur in a shared
# cache context. What happens to connection B if one connection A encounters
# an IO-error whilst reading or writing the file-system?
#
# $Id: shared_err.test,v 1.20 2008/07/07 14:56:57 danielk1977 Exp $

proc skip {args} {}


set testdir [file dirname $argv0]
source $testdir/tester.tcl
source $testdir/malloc_common.tcl







|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#
#***********************************************************************
#
# The focus of the tests in this file are IO errors that occur in a shared
# cache context. What happens to connection B if one connection A encounters
# an IO-error whilst reading or writing the file-system?
#
# $Id: shared_err.test,v 1.21 2008/07/07 17:55:29 danielk1977 Exp $

proc skip {args} {}


set testdir [file dirname $argv0]
source $testdir/tester.tcl
source $testdir/malloc_common.tcl
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
    }
  } {1}

# db2 eval {select * from sqlite_master}
  db2 close
}

# Only run these tests if memory debugging is turned on.
#
ifcapable !memdebug {
   puts "Skipping tests shared_err-4 through -9:\
         not compiled with -DSQLITE_MEMDEBUG..."
   db close
   sqlite3_enable_shared_cache $::enable_shared_cache
   finish_test
   return
}

# Provoke a malloc() failure when a cursor position is being saved. This
# only happens with index cursors (because they malloc() space to save the
# current key value). It does not happen with tables, because an integer
# key does not require a malloc() to store. 
#
# The library should return an SQLITE_NOMEM to the caller. The query that
# owns the cursor (the one for which the position is not saved) should







<
<
<
<
<
<
<
<
<
<
<







287
288
289
290
291
292
293











294
295
296
297
298
299
300
    }
  } {1}

# db2 eval {select * from sqlite_master}
  db2 close
}












# Provoke a malloc() failure when a cursor position is being saved. This
# only happens with index cursors (because they malloc() space to save the
# current key value). It does not happen with tables, because an integer
# key does not require a malloc() to store. 
#
# The library should return an SQLITE_NOMEM to the caller. The query that
# owns the cursor (the one for which the position is not saved) should
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
    ROLLBACK;
  }
} -cleanup {
  do_test shared_malloc-8.$::n.cleanup.1 {
    set res [catchsql {SELECT a FROM t1} db2]
    set ans [lindex $res 1]
    if {[lindex $res 0]} {
       set r [expr {$ans=="disk I/O error"}]
    } else {
       set r [expr {[lrange $ans 0 1]=="0000000000 1111111111"}]
    }
  } {1}
  do_test shared_malloc-8.$::n.cleanup.2 {
    set rc1 [sqlite3_step $::STMT]
    set rc2 [sqlite3_finalize $::STMT]







|







401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
    ROLLBACK;
  }
} -cleanup {
  do_test shared_malloc-8.$::n.cleanup.1 {
    set res [catchsql {SELECT a FROM t1} db2]
    set ans [lindex $res 1]
    if {[lindex $res 0]} {
       set r [expr {$ans=="disk I/O error" || $ans=="out of memory"}]
    } else {
       set r [expr {[lrange $ans 0 1]=="0000000000 1111111111"}]
    }
  } {1}
  do_test shared_malloc-8.$::n.cleanup.2 {
    set rc1 [sqlite3_step $::STMT]
    set rc2 [sqlite3_finalize $::STMT]
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
  } {1}
  db2 close
}
do_test shared_malloc-8.X {
  # Test that one or more queries were aborted due to the malloc() failure.
  expr $::aborted>=1
} {1}


# This test is designed to catch a specific bug that was present during
# development of 3.5.0. If a malloc() failed while setting the page-size,
# a buffer (Pager.pTmpSpace) was being freed. This could cause a seg-fault
# later if another connection tried to use the pager.
#
# This test will crash 3.4.2.







<







425
426
427
428
429
430
431

432
433
434
435
436
437
438
  } {1}
  db2 close
}
do_test shared_malloc-8.X {
  # Test that one or more queries were aborted due to the malloc() failure.
  expr $::aborted>=1
} {1}


# This test is designed to catch a specific bug that was present during
# development of 3.5.0. If a malloc() failed while setting the page-size,
# a buffer (Pager.pTmpSpace) was being freed. This could cause a seg-fault
# later if another connection tried to use the pager.
#
# This test will crash 3.4.2.
495
496
497
498
499
500
501



502
503
504
505
506
507
508
509
510
  catch {db eval {SELECT * FROM sqlite_master}}
  catch {sqlite3_errmsg16 db}
  error 1
} -cleanup {
  execsql { SELECT * FROM sqlite_master }
}




do_malloc_test shared_err-12 -sqlbody {
  CREATE TABLE abc(a, b, c);
  INSERT INTO abc VALUES(1, 2, 3);
}

catch {db close}
catch {db2 close}
sqlite3_enable_shared_cache $::enable_shared_cache
finish_test







>
>
>









483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
  catch {db eval {SELECT * FROM sqlite_master}}
  catch {sqlite3_errmsg16 db}
  error 1
} -cleanup {
  execsql { SELECT * FROM sqlite_master }
}

catch {db close}
catch {db2 close}

do_malloc_test shared_err-12 -sqlbody {
  CREATE TABLE abc(a, b, c);
  INSERT INTO abc VALUES(1, 2, 3);
}

catch {db close}
catch {db2 close}
sqlite3_enable_shared_cache $::enable_shared_cache
finish_test