]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix a problem causing false corruption reports following recovery of a *-wal file...
authordan <Dan Kennedy>
Mon, 27 Jun 2022 21:42:45 +0000 (21:42 +0000)
committerdan <Dan Kennedy>
Mon, 27 Jun 2022 21:42:45 +0000 (21:42 +0000)
FossilOrigin-Name: f6eafb65a43c650b065abe4a59e329c977cab1856c72dc9162046576d7bbfc8a

manifest
manifest.uuid
src/wal.c
test/wal2recover3.test [new file with mode: 0644]

index 3b4e819139175c3bdb2c96c122d756a10ea532d0..8cd56d9d96f2e6d282fc81e55395c058fc047ed6 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Merge\sversion\s3.39.0\sinto\sthe\swal2\sbranch.
-D 2022-06-25T16:53:36.816
+C Fix\sa\sproblem\scausing\sfalse\scorruption\sreports\sfollowing\srecovery\sof\sa\s*-wal\sfile\sthat\scontains\sone\sor\smore\stransactions\sand\sa\s*-wal2\sfile\sthat\scontains\sa\svalid\sheader\sbut\sno\svalid\stransactions.
+D 2022-06-27T21:42:45.196
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -656,7 +656,7 @@ F src/vdbetrace.c fe0bc29ebd4e02c8bc5c1945f1d2e6be5927ec12c06d89b03ef2a4def34bf8
 F src/vdbevtab.c f99b275366c5fc5e2d99f734729880994ab9500bdafde7fae3b02d562b9d323c
 F src/vtab.c 3d72c780d1ea08906a198e4f033921a658a54590e3ed72c544995d84f3f9464a
 F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
-F src/wal.c a9cc35881efbb97e568b654dffa2716cf4c5d3fd15489980ab96e48fc5bc60a7
+F src/wal.c f5fcbb7c5692690d877fb65f97f392cfd6a568e56c765c3f3f18bb9ed82409ed
 F src/wal.h d01234e828943e002040c22a7e017642962f9fd9b2dc142fa599769ae4e459e9
 F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b
 F src/where.c 9a44063e60d8f42dd9dc8147b8e8dcfc315bbd13e25c395211292c36d828c869
@@ -1773,6 +1773,7 @@ F test/wal2lock.test 0ef98d72dc6bcf7711dedd684760488400d9a9a6eec0dc5d38220604377
 F test/wal2openclose.test 2b26be723ea7f4263c8d5d70b37efd1c359561a0526e39466c45fe8e6478daee
 F test/wal2recover.test ba8f4bc9397c838734619f9e759bd98b00e355347b3cf80a2e677610d231d5d8
 F test/wal2recover2.test 0c46afc759e4392a3c12fba17432b880c93a13bf4246d1be5101b00bae4c5f01
+F test/wal2recover3.test 4a91689e165a38bc401736e6518188c2b0ff4fa1566d1810b8867536db128177
 F test/wal2rewrite.test 6ca6f631ffcf871240beab5f02608913fd075c6d0d31310b026c8383c65c9f9c
 F test/wal2rollback.test 23adc4a099b23f6aaea8b04fdca1c35861d887dd80f8be7da2d5273eb777e428
 F test/wal2savepoint.test 2c82bd6a6ee5066c156040d2e9c2415646fcf96116ae7ad127eaf0c0b4a85f22
@@ -1991,8 +1992,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 5a5e6e368f5cc8fe7cf29696a07942101f5c114084d4117acf277bb3ad8555ac 14e166f40dbfa6e055543f8301525f2ca2e96a02a57269818b9e69e162e98918
-R e5fc911f0a86748145e1da0886462030
-U drh
-Z 1da384b15e9d7950d5559005e2984b62
+P ad3a7005e704711fb9de9e96883db3aed82c4f132a66cb74daf67c2527d79f73
+R 5eb4043659412b932d516effbdde5301
+U dan
+Z 7526c786ad8a0ce3d92bc4d2c949f076
 # Remove this line to create a well-formed Fossil manifest.
index 5360f63fdd5d014e63a094b330ff4db7d866827c..b34953287d73a1d281bfb23598869d1461785a72 100644 (file)
@@ -1 +1 @@
-ad3a7005e704711fb9de9e96883db3aed82c4f132a66cb74daf67c2527d79f73
\ No newline at end of file
+f6eafb65a43c650b065abe4a59e329c977cab1856c72dc9162046576d7bbfc8a
\ No newline at end of file
index f8fb749c852d9fb124d79becead0cdc1a429c4b3..14c330a85c754f331aaa9a0a46645918eb77baa2 100644 (file)
--- a/src/wal.c
+++ b/src/wal.c
@@ -1827,7 +1827,8 @@ static int walIndexRecover(Wal *pWal){
     if( isOpen(pWal->apWalFd[1]) ){
       /* The case where *-wal2 may follow *-wal */
       if( nCkpt2<=0x0F && nCkpt2==nCkpt1+1 ){
-        if( sqlite3Get4byte((u8*)(&pWal->hdr.aSalt[0]))==hdr.aFrameCksum[0]
+        if( pWal->hdr.mxFrame
+         && sqlite3Get4byte((u8*)(&pWal->hdr.aSalt[0]))==hdr.aFrameCksum[0]
          && sqlite3Get4byte((u8*)(&pWal->hdr.aSalt[1]))==hdr.aFrameCksum[1]
         ){
           walidxSetFile(&pWal->hdr, 1);
@@ -1840,7 +1841,8 @@ static int walIndexRecover(Wal *pWal){
 
       /* When *-wal may follow *-wal2 */
       if( (nCkpt2==0x0F && nCkpt1==0) || (nCkpt2<0x0F && nCkpt2==nCkpt1-1) ){
-        if( sqlite3Get4byte((u8*)(&hdr.aSalt[0]))==pWal->hdr.aFrameCksum[0]
+        if( hdr.mxFrame
+         && sqlite3Get4byte((u8*)(&hdr.aSalt[0]))==pWal->hdr.aFrameCksum[0]
          && sqlite3Get4byte((u8*)(&hdr.aSalt[1]))==pWal->hdr.aFrameCksum[1]
         ){
           SWAP(WalIndexHdr, pWal->hdr, hdr);
diff --git a/test/wal2recover3.test b/test/wal2recover3.test
new file mode 100644 (file)
index 0000000..eab3011
--- /dev/null
@@ -0,0 +1,52 @@
+# 2022 June 28
+#
+# The author disclaims copyright to this source code.  In place of
+# a legal notice, here is a blessing:
+#
+#    May you do good and not evil.
+#    May you find forgiveness for yourself and forgive others.
+#    May you share freely, never taking more than you give.
+#
+#***********************************************************************
+# This file implements regression tests for SQLite library.  The
+# focus of this file is testing the operation of the library in
+# "PRAGMA journal_mode=WAL2" mode.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+source $testdir/lock_common.tcl
+source $testdir/malloc_common.tcl
+source $testdir/wal_common.tcl
+
+set testprefix wal2recover3
+ifcapable !wal {finish_test ; return }
+
+do_execsql_test 1.0 {
+  CREATE TABLE t1(x);
+  CREATE TABLE t2(x);
+  PRAGMA journal_mode = wal2;
+  PRAGMA wal_autocheckpoint = 0;
+  PRAGMA journal_size_limit = 10000;
+} {wal2 0 10000}
+
+do_execsql_test 1.1 {
+  WITH s(i) AS ( VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<1500 )
+    INSERT INTO t1 SELECT i FROM s;
+  WITH s(i) AS ( VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<1500 )
+    INSERT INTO t2 SELECT i FROM s;
+}
+
+db_save_and_close
+set fd [open sv_test.db-wal2 r+]
+seek $fd 4000
+puts -nonewline $fd 0
+close $fd
+
+db_restore_and_reopen
+do_execsql_test 1.2 {
+  SELECT sql FROM sqlite_schema;
+} {{CREATE TABLE t1(x)} {CREATE TABLE t2(x)}}
+
+finish_test
+