corruptA.test 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. set testdir [file dirname $argv0]
  19. source $testdir/tester.tcl
  20. # Do not use a codec for tests in this file, as the database file is
  21. # manipulated directly using tcl scripts (using the [hexio_write] command).
  22. #
  23. do_not_use_codec
  24. # Create a database to work with.
  25. #
  26. do_test corruptA-1.1 {
  27. execsql {
  28. CREATE TABLE t1(x);
  29. INSERT INTO t1(x) VALUES(1);
  30. }
  31. expr {[file size test.db]>=1024}
  32. } {1}
  33. integrity_check corruptA-1.2
  34. # Corrupt the file header in various ways and make sure the corruption
  35. # is detected when opening the database file.
  36. #
  37. db close
  38. forcecopy test.db test.db-template
  39. set unreadable_version 02
  40. ifcapable wal { set unreadable_version 03 }
  41. do_test corruptA-2.1 {
  42. forcecopy test.db-template test.db
  43. hexio_write test.db 19 $unreadable_version ;# the read format number
  44. sqlite3 db test.db
  45. catchsql {SELECT * FROM t1}
  46. } {1 {file is encrypted or is not a database}}
  47. do_test corruptA-2.2 {
  48. db close
  49. forcecopy test.db-template test.db
  50. hexio_write test.db 21 41 ;# max embedded payload fraction
  51. sqlite3 db test.db
  52. catchsql {SELECT * FROM t1}
  53. } {1 {file is encrypted or is not a database}}
  54. do_test corruptA-2.3 {
  55. db close
  56. forcecopy test.db-template test.db
  57. hexio_write test.db 22 1f ;# min embedded payload fraction
  58. sqlite3 db test.db
  59. catchsql {SELECT * FROM t1}
  60. } {1 {file is encrypted or is not a database}}
  61. do_test corruptA-2.4 {
  62. db close
  63. forcecopy test.db-template test.db
  64. hexio_write test.db 23 21 ;# min leaf payload fraction
  65. sqlite3 db test.db
  66. catchsql {SELECT * FROM t1}
  67. } {1 {file is encrypted or is not a database}}
  68. finish_test