fts5faultB.test 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. # 2016 February 17
  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. # This file is focused on OOM errors.
  13. #
  14. source [file join [file dirname [info script]] fts5_common.tcl]
  15. source $testdir/malloc_common.tcl
  16. set testprefix fts5faultB
  17. # If SQLITE_ENABLE_FTS3 is defined, omit this file.
  18. ifcapable !fts5 {
  19. finish_test
  20. return
  21. }
  22. proc mit {blob} {
  23. set scan(littleEndian) i*
  24. set scan(bigEndian) I*
  25. binary scan $blob $scan($::tcl_platform(byteOrder)) r
  26. return $r
  27. }
  28. db func mit mit
  29. #-------------------------------------------------------------------------
  30. # Errors while registering the matchinfo() demo function.
  31. #
  32. do_faultsim_test 1 -faults oom* -prep {
  33. sqlite3 db test.db
  34. } -body {
  35. sqlite3_fts5_register_matchinfo db
  36. } -test {
  37. faultsim_test_result {0 {}} {1 SQLITE_ERROR} {1 SQLITE_NOMEM}
  38. }
  39. #-------------------------------------------------------------------------
  40. # Errors while executing the matchinfo() demo function.
  41. #
  42. reset_db
  43. sqlite3_fts5_register_matchinfo db
  44. db func mit mit
  45. do_execsql_test 2 {
  46. CREATE VIRTUAL TABLE t1 USING fts5(a, b);
  47. INSERT INTO t1 VALUES('x y z', '1 2 3');
  48. INSERT INTO t1 VALUES('x', '1 2 3 4 5 6 7');
  49. }
  50. do_faultsim_test 2.1 -faults oom* -body {
  51. execsql { SELECT mit(matchinfo(t1, 'a')) FROM t1('x') }
  52. } -test {
  53. faultsim_test_result {0 {{2 5} {2 5}}}
  54. }
  55. do_faultsim_test 2.2 -faults oom* -body {
  56. execsql { SELECT mit(matchinfo(t1, 'l')) FROM t1('x') }
  57. } -test {
  58. faultsim_test_result {0 {{3 3} {1 7}}}
  59. }
  60. do_execsql_test 2.3 {
  61. INSERT INTO t1 VALUES('a b c d e f', 'a b d e f c');
  62. INSERT INTO t1 VALUES('l m b c a', 'n o a b c z');
  63. }
  64. do_faultsim_test 2.4 -faults oom* -body {
  65. execsql { SELECT mit(matchinfo(t1, 's')) FROM t1('a b c') }
  66. } -test {
  67. faultsim_test_result {0 {{3 2} {2 3}}}
  68. }
  69. #-------------------------------------------------------------------------
  70. #
  71. reset_db
  72. do_execsql_test 3.0 {
  73. CREATE VIRTUAL TABLE x1 USING fts5(z);
  74. }
  75. do_faultsim_test 3.1 -faults oom* -body {
  76. execsql {
  77. SELECT rowid FROM x1('c') WHERE rowid>1;
  78. }
  79. } -test {
  80. faultsim_test_result {0 {}}
  81. }
  82. do_execsql_test 3.2 {
  83. INSERT INTO x1 VALUES('a b c');
  84. INSERT INTO x1 VALUES('b c d');
  85. INSERT INTO x1 VALUES('c d e');
  86. INSERT INTO x1 VALUES('d e f');
  87. }
  88. do_faultsim_test 3.3 -faults oom* -body {
  89. execsql {
  90. SELECT rowid FROM x1('c') WHERE rowid>1;
  91. }
  92. } -test {
  93. faultsim_test_result {0 {2 3}}
  94. }
  95. #-------------------------------------------------------------------------
  96. # Test OOM injection with nested colsets.
  97. #
  98. reset_db
  99. do_execsql_test 4.0 {
  100. CREATE VIRTUAL TABLE t1 USING fts5(a, b, c, d);
  101. INSERT INTO t1 VALUES('a', 'b', 'c', 'd'); -- 1
  102. INSERT INTO t1 VALUES('d', 'a', 'b', 'c'); -- 2
  103. INSERT INTO t1 VALUES('c', 'd', 'a', 'b'); -- 3
  104. INSERT INTO t1 VALUES('b', 'c', 'd', 'a'); -- 4
  105. }
  106. do_faultsim_test 4.1 -faults oom* -body {
  107. execsql { SELECT rowid FROM t1('{a b c} : (b:a AND c:b)'); }
  108. } -test {
  109. faultsim_test_result {0 2}
  110. }
  111. do_faultsim_test 4.2 -faults oom* -body {
  112. execsql { SELECT rowid FROM t1('{a b c} : (a AND d)') }
  113. } -test {
  114. faultsim_test_result {0 {2 3}}
  115. }
  116. #-------------------------------------------------------------------------
  117. # Test OOM injection while parsing a CARET expression
  118. #
  119. reset_db
  120. do_execsql_test 5.0 {
  121. CREATE VIRTUAL TABLE t1 USING fts5(a);
  122. INSERT INTO t1 VALUES('a b c d'); -- 1
  123. INSERT INTO t1 VALUES('d a b c'); -- 2
  124. INSERT INTO t1 VALUES('c d a b'); -- 3
  125. INSERT INTO t1 VALUES('b c d a'); -- 4
  126. }
  127. do_faultsim_test 5.1 -faults oom* -body {
  128. execsql { SELECT rowid FROM t1('^a OR ^b') }
  129. } -test {
  130. faultsim_test_result {0 {1 4}}
  131. }
  132. #-------------------------------------------------------------------------
  133. # Test OOM injection in a query with two MATCH expressions
  134. #
  135. reset_db
  136. do_execsql_test 6.0 {
  137. CREATE VIRTUAL TABLE t1 USING fts5(a);
  138. INSERT INTO t1 VALUES('a b c d'); -- 1
  139. INSERT INTO t1 VALUES('d a b c'); -- 2
  140. INSERT INTO t1 VALUES('c d a b'); -- 3
  141. INSERT INTO t1 VALUES('b c d a'); -- 4
  142. }
  143. do_faultsim_test 6.1 -faults oom* -body {
  144. execsql { SELECT rowid FROM t1 WHERE t1 MATCH 'a' AND t1 MATCH 'b' }
  145. } -test {
  146. faultsim_test_result {0 {1 2 3 4}}
  147. }
  148. do_faultsim_test 6.2 -faults oom* -body {
  149. execsql { SELECT rowid FROM t1 WHERE t1 MATCH 'a OR b' AND t1 MATCH 'c OR d' }
  150. } -test {
  151. faultsim_test_result {0 {1 2 3 4}}
  152. }
  153. finish_test