fts5corrupt7.test 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. # 2023 April 30
  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. #
  12. source [file join [file dirname [info script]] fts5_common.tcl]
  13. set testprefix fts5corrupt7
  14. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  15. ifcapable !fts5 {
  16. finish_test
  17. return
  18. }
  19. sqlite3_fts5_may_be_corrupt 1
  20. do_execsql_test 1.0 {
  21. CREATE VIRTUAL TABLE t1 USING fts5(x);
  22. INSERT INTO t1(t1, rank) VALUES('pgsz', 32);
  23. }
  24. set doc [string repeat "a b " 30]
  25. do_execsql_test 1.1 {
  26. BEGIN;
  27. INSERT INTO t1(rowid, x) VALUES(123, $doc);
  28. INSERT INTO t1(rowid, x) VALUES(124, $doc);
  29. COMMIT;
  30. }
  31. execsql_pp {
  32. SELECT id, fts5_decode(id, block), quote(block) FROM t1_data
  33. }
  34. set rows [db eval { SELECT rowid FROM t1_data }]
  35. db_save_and_close
  36. foreach r $rows {
  37. db_restore_and_reopen
  38. proc edit_block {b} {
  39. binary scan $b c* in
  40. set out [lreplace $in 0 1 255 255]
  41. binary format c* $out
  42. }
  43. db func edit_block edit_block
  44. do_execsql_test 1.2.$r.1 {
  45. UPDATE t1_data SET block = edit_block(block) WHERE rowid=$r;
  46. }
  47. do_execsql_test 1.2.$r.2 {
  48. INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
  49. }
  50. do_test 1.2.$r.3 {
  51. catchsql { DELETE FROM t1 WHERE rowid=123; }
  52. catchsql { DELETE FROM t1 WHERE rowid=124; }
  53. set {} {}
  54. } {}
  55. db close
  56. }
  57. foreach r $rows {
  58. set r 137438953475
  59. db_restore_and_reopen
  60. proc edit_block {b} {
  61. binary scan $b c* in
  62. set out [lreplace $in end end 127]
  63. binary format c* $out
  64. }
  65. db func edit_block edit_block
  66. do_execsql_test 1.2.$r.1 {
  67. UPDATE t1_data SET block = edit_block(block) WHERE rowid=$r;
  68. }
  69. do_execsql_test 1.2.$r.2 {
  70. INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
  71. }
  72. do_test 1.2.$r.3 {
  73. catchsql { DELETE FROM t1 WHERE rowid=124; }
  74. catchsql { DELETE FROM t1 WHERE rowid=123; }
  75. set {} {}
  76. } {}
  77. db close
  78. }
  79. #-------------------------------------------------------------------------
  80. reset_db
  81. do_execsql_test 2.0 {
  82. CREATE VIRTUAL TABLE t1 USING fts5(x);
  83. BEGIN;
  84. INSERT INTO t1 VALUES('abc');
  85. INSERT INTO t1 VALUES('b d d d');
  86. COMMIT;
  87. INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
  88. }
  89. execsql_pp {
  90. SELECT id, quote(block) FROM t1_data
  91. }
  92. do_execsql_test 2.1 {
  93. SELECT quote(block) FROM t1_data WHERE id > 10;
  94. } {X'0000001A04306162630102020101620202020101640206030303040806'}
  95. do_execsql_test 2.2 {
  96. UPDATE t1_data SET
  97. block=X'0000001A04306162630102025501620202020101640206030303040806'
  98. WHERE id>10
  99. }
  100. do_catchsql_test 2.3 {
  101. DELETE FROM t1 WHERE rowid = 1
  102. } {1 {database disk image is malformed}}
  103. finish_test