]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Merge latest trunk changes into this branch.
authordan <Dan Kennedy>
Wed, 4 Mar 2026 11:08:10 +0000 (11:08 +0000)
committerdan <Dan Kennedy>
Wed, 4 Mar 2026 11:08:10 +0000 (11:08 +0000)
FossilOrigin-Name: 947411e56c009b8212c406eff187ddf1cace7869ebcb7d12192bdb38f2d6f6c9

1  2 
Makefile.msc
main.mk
manifest
manifest.uuid
src/pager.c
src/wal.c

diff --cc Makefile.msc
Simple merge
diff --cc main.mk
Simple merge
diff --cc manifest
index c1f00e8d098b1ef3ad5b3385230cdfd53927b4ed,ea0c2eff2dbdde7efe5569de18a343fadd425c9c..c14b9d71f0acb68c4721de9ea873baf379198c05
+++ b/manifest
@@@ -1,12 -1,12 +1,12 @@@
- C Merge\sthe\slatest\strunk\senhancements\sinto\sthe\swal2\sbranch.
- D 2026-02-17T16:18:59.015
 -C Avoid\san\sobscure\srace\scondition\sbetween\sa\scheckpointer\sand\sa\swriter\swrapping\saround\sto\sthe\sstart\sof\sthe\swal\sfile.
 -D 2026-03-03T19:43:19.771
++C Merge\slatest\strunk\schanges\sinto\sthis\sbranch.
++D 2026-03-04T11:08:10.322
  F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
  F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
  F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
  F LICENSE.md 6bc480fc673fb4acbc4094e77edb326267dd460162d7723c7f30bee2d3d9e97d
  F Makefile.in 3ce07126d7e87c7464301482e161fdae6a51d0a2aa06b200b8f0000ef4d6163b
  F Makefile.linux-generic bd3e3cacd369821a6241d4ea1967395c962dfe3057e38cb0a435cee0e8b789d0
- F Makefile.msc 651f037e143d940b996b48fad0f773eb3bf5fab148af3e98aa2730c812c16e8b
 -F Makefile.msc 174764cb7e80c80f9003c46b3e388d74c68c8c40230208904b3af8fcabee5f4e
++F Makefile.msc a93b6ae1760f37ad0743607877a314c5cf7edb716726fc853cb2b8bf384ebcf1
  F README.md 3fa51fc7ababc32edd175ae8b2986c86d5ea120c1cb1e57c7f7849492d1405ec
  F VERSION 74672bfd4c7826c0fc6f84762488a707c52e7d2d94af42ccb0edcc6c74311c41
  F art/icon-243x273.gif 9750b734f82fdb3dc43127753d5e6fbf3b62c9f4e136c2fbf573b2f57ea87af5
@@@ -662,7 -651,7 +653,7 @@@ F ext/wasm/tests/opfs/sahpool/index.htm
  F ext/wasm/tests/opfs/sahpool/sahpool-pausing.js f264925cfc82155de38cecb3d204c36e0f6991460fff0cb7c15079454679a4e2
  F ext/wasm/tests/opfs/sahpool/sahpool-worker.js bd25a43fc2ab2d1bafd8f2854ad3943ef673f7c3be03e95ecf1612ff6e8e2a61
  F magic.txt 5ade0bc977aa135e79e3faaea894d5671b26107cc91e70783aa7dc83f22f3ba0
- F main.mk c1b73927c4e4362d644449bc78c0a8e4d99ce80467ff76191ebfe94b8a483062
 -F main.mk e1a03e9206f6a042a9147035915cb944e9242d570779bc3ccd7ed6a39df10cae
++F main.mk 2f89ad787bd2c35ec8f12751997b95126bd3d229691dfd8dfc87c97668c3ea95
  F make.bat a136fd0b1c93e89854a86d5f4edcf0386d211e5d5ec2434480f6eea436c7420c
  F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271
  F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504
@@@ -725,18 -714,18 +716,18 @@@ F src/os.h 1ff5ae51d339d0e30d8a9d814f4b
  F src/os_common.h 6c0eb8dd40ef3e12fe585a13e709710267a258e2c8dd1c40b1948a1d14582e06
  F src/os_kv.c e7d96727db5b67e39d590a68cc61c86daf4c093c36c011a09ebfb521182ec28d
  F src/os_setup.h 8efc64eda6a6c2f221387eefc2e7e45fd5a3d5c8337a7a83519ba4fbd2957ae2
- F src/os_unix.c dcf7988ddbdd68619b821c9a722f9377abb46f1d26c9279eb5a50402fd43d749
+ F src/os_unix.c fa5e09b4df35ad845440cad67b86908cfe1fd4c28c51915f82e23633d1992bf4
  F src/os_win.c 0d553b6e8b92c8eb85e7f1b4a8036fe8638c8b32c9ad8d9d72a861c10f81b4c5
  F src/os_win.h 5e168adf482484327195d10f9c3bce3520f598e04e07ffe62c9c5a8067c1037b
- F src/pager.c 4d20119a16fbaca6534640044cf3f96042f73aa823f0121be02dd94f0094ab72
 -F src/pager.c fe34fd22ec251436985d7b6ebdd05bf238a17901c2cb23d3d28974dd2361a912
 -F src/pager.h 6137149346e6c8a3ddc1eeb40aee46381e9bc8b0fcc6dda8a1efde993c2275b8
++F src/pager.c ac55710d5c1ffcc650677d4596305ff9470ba9191266ac015e4eb1f0a5a6871d
 +F src/pager.h fc0c95d27f2aefffcb39b4373b3557e89e1b4b9a36b183cc04d6f22002bf0ad2
- F src/parse.y 7c2184b5665c671258c4e96a10bbc9dbf7e1ede462ebc4e614249de0d54c8a26
+ F src/parse.y 3b784d6083380a950e3b1b32ce5ddd303e8c7c209d8ab788df2c62aaf9ee8eb3
  F src/pcache.c 588cc3c5ccaaadde689ed35ce5c5c891a1f7b1f4d1f56f6cf0143b74d8ee6484
- F src/pcache.h 1497ce1b823cf00094bb0cf3bac37b345937e6f910890c626b16512316d3abf5
+ F src/pcache.h 092b758d2c5e4dabb30eae46d8dfad77c0f70b16bf3ff1943f7a232b0fe0d4ba
  F src/pcache1.c 131ca0daf4e66b4608d2945ae76d6ed90de3f60539afbd5ef9ec65667a5f2fcd
 -F src/pragma.c ecec75795c1821520266e4f93fa8840cce48979af532db06f085e36a7813860f
 +F src/pragma.c ab340f5e412cb46da58d159fd57a70d6696578b5b39664fb44064279b4d20a33
  F src/prepare.c f6a6e28a281bd1d1da12f47d370a81af46159b40f73bf7fa0b276b664f9c8b7d
- F src/printf.c b1b29b5e58e1530d5daeee5963d3c318d8ab2d7e38437580e28755753e0c1ded
+ F src/printf.c 9cff219dba73b1aa9a8113e83e962f03f7bea8b6eb51cefb25bc468d5a69fb2d
  F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
  F src/resolve.c 928ff887f2a7c64275182060d94d06fdddbe32226c569781cf7e7edc6f58d7fd
  F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97
@@@ -805,24 -794,24 +796,24 @@@ F src/trigger.c 4bf3bfb3851d165e4404a9f
  F src/update.c 3e5e7ff66fa19ebe4d1b113d480639a24cc1175adbefabbd1a948a07f28e37cf
  F src/upsert.c 215328c3f91623c520ec8672c44323553f12caeb4f01b1090ebdca99fdf7b4f1
  F src/utf.c 7267c3fb9e2467020507601af3354c2446c61f444387e094c779dccd5ca62165
- F src/util.c 10572efe1bcf43fc2f6015cfba6126a4a5e32e7d6478a946a2b27d5ce189328b
+ F src/util.c eccfa8b3b414bb64c6543421c9fd10e5f07e103baae36427a273a9131527694c
  F src/vacuum.c d3d35d8ae893d419ade5fa196d761a83bddcbb62137a1a157ae751ef38b26e82
 -F src/vdbe.c 5328c99dd256ee8132383565a86e253543a85daccfd7477c52f20bac6b385a7f
 +F src/vdbe.c 577d735e735bfc09da7701acd9c51223080bcd12882a418a400ca0d36d888e12
  F src/vdbe.h 966d0677a540b7ea6549b7c4e1312fc0d830fce3a235a58c801f2cc31cf5ecf9
  F src/vdbeInt.h 42488247a80cd9d300627833c6c85ace067ae5011a99e7614e2358130d62feea
  F src/vdbeapi.c 6cdcbe5c7afa754c998e73d2d5d2805556268362914b952811bdfb9c78a37cf1
 -F src/vdbeaux.c 396d38a62a357b807eabae0cae441fc89d2767a57ab08026b7072bf7aa2dd00c
 +F src/vdbeaux.c df883876635d6d876c29c1690c874849bed3fd371ea909b2334a52532e575027
  F src/vdbeblob.c b3f0640db9642fbdc88bd6ebcc83d6009514cafc98f062f675f2c8d505d82692
- F src/vdbemem.c bdfda8e65933cfee34aa29c2bfa31fc07609f3d56d147aa8a367a297533d33d1
+ F src/vdbemem.c 317ec5e870ddb16951b606c9fe8be22baef22ecbe46f58fdefc259662238afb7
  F src/vdbesort.c b69220f4ea9ffea5fdef34d968c60305444eea909252a81933b54c296d9cca70
  F src/vdbetrace.c 49e689f751505839742f4a243a1a566e57d5c9eaf0d33bbaa26e2de3febf7b41
  F src/vdbevtab.c fc46b9cbd759dc013f0b3724549cc0d71379183c667df3a5988f7e2f1bd485f3
  F src/vtab.c 5437ce986db2f70e639ce8a3fe68dcdfe64b0f1abb14eaebecdabd5e0766cc68
  F src/vxworks.h 9d18819c5235b49c2340a8a4d48195ec5d5afb637b152406de95a9436beeaeab
- F src/wal.c e99e9defaca6f78c2bf50994f8afc2f4a5f7f315559a23b8398b2398a7dd192e
 -F src/wal.c 88d94fd15a75f6eda831fa32d1148a267ea37bf0a4b69829a73dfde06244b08f
 -F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452
++F src/wal.c 0f813d54656eb40d465077947cf523d0f6672e215d8c00e06b86459f58eb5634
 +F src/wal.h 97b8a9903387401377b59507e86b93a148ef1ad4e5ce0f23659a12dcdce56af2
  F src/walker.c d5006d6b005e4ea7302ad390957a8d41ed83faa177e412f89bc5600a7462a014
- F src/where.c 7a7fe745dd8104d0276a3d3f6e6ac7f087af3dd9f34a90bc937e5e7aea817e15
+ F src/where.c 9f09ee7b260010138d5f9fb5f195b98051119eae3096a99d72ff16c83230f4af
  F src/whereInt.h 8d94cb116c9e06205c3d5ac87af065fc044f8cf08bfdccd94b6ea1c1308e65da
  F src/wherecode.c 783ecd30061c875c919a5163e4b55f9a0eccdaf7c9b17ad2908a1668a8766bc4
  F src/whereexpr.c e9f7185fba366d9365aa7a97329609e4cf00b3dd0400d069fbaa5187350c17c6
@@@ -1713,10 -1705,10 +1707,10 @@@ F test/temptable2.test 76821347810ecc88
  F test/temptable3.test d11a0974e52b347e45ee54ef1923c91ed91e4637
  F test/temptrigfault.tes fc5918e64f3867156fefe7cfca9d8e1f495134a5229b2b511b0dc11c07f2eab4
  F test/temptrigger.test a00f258ed8d21a0e8fd4f322f15e8cfb5cef2e43655670e07a753e3fb4769d61
 -F test/tester.tcl 2d943f60200e0a36bcd3f1f0baf181a751cd3604ef6b6bd4c8dc39b4e8a53116
 +F test/tester.tcl 7a86598eed39bfbfc5dea5f1c35c3e6b0843b2155188ec6f5ed4d2c9fb9d841c
  F test/testloadext.c 862b848783eaed9985fbce46c65cd214664376b549fae252b364d5d1ef350a27
  F test/testrunner.tcl 78d67079fc39caf2af3fd9d4c30bdac78dae7ec50b9fc802835e7a5189581e07 x
- F test/testrunner_data.tcl 87b8afd37c8e517fa87b7936540b2fc1ede8291f0567fb88744b9bff272a2e8b
+ F test/testrunner_data.tcl 078e251983c8fc573567125147655f68132210f226c92922daf21fb913779717
  F test/testrunner_estwork.tcl 81e2ae10238f50540f42fbf2d94913052a99bfb494b69e546506323f195dcff9
  F test/thread001.test a0985c117eab62c0c65526e9fa5d1360dd1cac5b03bde223902763274ce21899
  F test/thread002.test c24c83408e35ba5a952a3638b7ac03ccdf1ce4409289c54a050ac4c5f1de7502
@@@ -2023,7 -2003,8 +2017,8 @@@ F test/walnoshm.test 844b3eb7d8e8ee76c8
  F test/waloverwrite.test dad2f26567f1b45174e54fbf9a8dc1cb876a7f03
  F test/walpersist.test 8d78a1ec91299163451417b451a2bac3481f8eb9f455b1ca507a6625c927ca6e
  F test/walprotocol.test 1b3f922125e341703f6e946d77fdc564d38fb3e07a9385cfdc6c99cac1ecf878
 -F test/walprotocol2.test 7d3b6b4bf0b12f8007121b1e6ef714bc99101fb3b48e46371df1db868eebc131
 +F test/walprotocol2.test 7e4bedd5ee83607e2928ac438bf7332a396b980d3e02aa0746509ce11ad1f13c
+ F test/walrestart.test 3b0a9198ad2eb9f716d8f3846b133ba9f4619fb56decb1e67bba27743c766289
  F test/walro.test 78a84bc0fdae1385c06b017215c426b6845734d6a5a3ac75c918dd9b801b1b9d
  F test/walro2.test 33955a6fd874dd9724005e17f77fef89d334b3171454a1256fe4941a96766cdc
  F test/walrofault.test c70cb6e308c443867701856cce92ad8288cd99488fa52afab77cca6cfd51af68
@@@ -2208,8 -2189,9 +2203,8 @@@ F tool/warnings-clang.sh bbf6a1e685e534
  F tool/warnings.sh d924598cf2f55a4ecbc2aeb055c10bd5f48114793e7ba25f9585435da29e7e98
  F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
  F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c
- P f65432340ff5845753ceac9045807fee429de92f31084428fdddac2f3fdd0048 091bd90ed5a6a326fd532e93bd17903e052476da14dc6aee2599a9acf75a3276
- R 7c2ed4420297f170ae96e462f214d1c5
- U drh
- Z 3faa53aa66ecce93882924a3e9d0f3b8
 -P 88dce64242552e7443d9fb496f6f3ad71dc5b4a882ce21b7ef1d5ea4e26f1e61 703cbb0f760515eac1e6f72a5e5cd928258c71378e4a976082b6518c90128135
 -R 081029f3feecf24cb4be31bd4056634e
 -T +closed 703cbb0f760515eac1e6f72a5e5cd928258c71378e4a976082b6518c90128135
++P 4ab288bd4a0b83e988121c6f46ecea0bd19244b62b2c3010ce3f4bf449de6136 7168988acbec2d8d51106a263e553f8942b8b23d983dbbe5028e0f9be68cbb83
++R 9ee5114c99df1e74ea0a831f5bdb20d4
+ U dan
 -Z aa660315ed5ec6682f68be7645c0d8b8
++Z ccb71c0e2766033118391073dcd47092
  # Remove this line to create a well-formed Fossil manifest.
diff --cc manifest.uuid
index 1b3df88d83d9fffb970b3f65df42a9acad7a7355,5e463bf5c673444ed7cc62197a003caf4bdbf4ee..4619b6428a8250cc773aaa637576cdf502ee5a45
@@@ -1,1 -1,1 +1,1 @@@
- 4ab288bd4a0b83e988121c6f46ecea0bd19244b62b2c3010ce3f4bf449de6136
 -7168988acbec2d8d51106a263e553f8942b8b23d983dbbe5028e0f9be68cbb83
++947411e56c009b8212c406eff187ddf1cace7869ebcb7d12192bdb38f2d6f6c9
diff --cc src/pager.c
Simple merge
diff --cc src/wal.c
index b1ff194f397f495ce553c629b420e82eea63e297,7f7bee62627aed6b3c4c8362e69a7d30a1141897..269d3555d82854a8e924ee4c791468aa040f1076
+++ b/src/wal.c
@@@ -2844,84 -2250,87 +2844,104 @@@ static int walCheckpoint
        assert( rc==SQLITE_OK || pIter==0 );
      }
  
 -    if( pIter
 -     && (rc = walBusyLock(pWal,xBusy,pBusyArg,WAL_READ_LOCK(0),1))==SQLITE_OK
 -    ){
 +    if( pIter && (bWal2 
 +     || (rc = walBusyLock(pWal, xBusy, pBusyArg,WAL_READ_LOCK(0),1))==SQLITE_OK
 +    )){
        u32 nBackfill = pInfo->nBackfill;
 +      assert( bWal2==0 || nBackfill==0 );
-       pInfo->nBackfillAttempted = mxSafeFrame; SEH_INJECT_FAULT;
-       /* Sync the wal file being checkpointed to disk */
-       rc = sqlite3OsSync(pWalFd, CKPT_SYNC_FLAGS(sync_flags));
-       /* If the database may grow as a result of this checkpoint, hint
-       ** about the eventual size of the db file to the VFS layer.  */
-       if( rc==SQLITE_OK ){
-         i64 nReq = ((i64)mxPage * szPage);
-         i64 nSize;                    /* Current size of database file */
-         sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_CKPT_START, 0);
-         rc = sqlite3OsFileSize(pWal->pDbFd, &nSize);
-         if( rc==SQLITE_OK && nSize<nReq ){
-           i64 mx = pWal->hdr.mxFrame + (bWal2?walidxGetMxFrame(&pWal->hdr,1):0);
+       WalIndexHdr *pLive = (WalIndexHdr*)walIndexHdr(pWal);
+       /* Now that read-lock slot 0 is locked, check that the wal has not been
+       ** wrapped since the header was read for this checkpoint. If it was, then
+       ** there was no work to do anyway.  In this case the
+       ** (pInfo->nBackfill<pWal->hdr.mxFrame) test above only passed because
+       ** pInfo->nBackfill had already been set to 0 by the writer that wrapped
+       ** the wal file. It would also be dangerous to proceed, as there may be
 -      ** fewer than pWal->hdr.mxFrame valid frames in the wal file.  */
++      ** fewer than pWal->hdr.mxFrame valid frames in the wal file. 
++      **
++      ** This check is not required in wal mode, as the checkpointer has
++      ** and writers never operate on the same file. And are prevented by
++      ** locks from doing so. But it does not hurt to leave it in.  */
+       int bChg = memcmp(pLive->aSalt, pWal->hdr.aSalt, sizeof(pWal->hdr.aSalt));
+       if( 0==bChg ){
+         pInfo->nBackfillAttempted = mxSafeFrame; SEH_INJECT_FAULT;
+   
 -        /* Sync the WAL to disk */
 -        rc = sqlite3OsSync(pWal->pWalFd, CKPT_SYNC_FLAGS(sync_flags));
++        /* Sync the wal file being checkpointed to disk */
++        rc = sqlite3OsSync(pWalFd, CKPT_SYNC_FLAGS(sync_flags));
+   
+         /* If the database may grow as a result of this checkpoint, hint
+         ** about the eventual size of the db file to the VFS layer.
+         */
+         if( rc==SQLITE_OK ){
+           i64 nReq = ((i64)mxPage * szPage);
+           i64 nSize;                    /* Current size of database file */
+           sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_CKPT_START, 0);
+           rc = sqlite3OsFileSize(pWal->pDbFd, &nSize);
+           if( rc==SQLITE_OK && nSize<nReq ){
 -            if( (nSize+65536+(i64)pWal->hdr.mxFrame*szPage)<nReq ){
++            i64 mx = pWal->hdr.mxFrame + (bWal2?walidxGetMxFrame(&pWal->hdr,1):0);
 +          if( (nSize+65536+mx*szPage)<nReq ){
-             /* If the size of the final database is larger than the current
-             ** database plus the amount of data in the wal file, plus the
-             ** maximum size of the pending-byte page (65536 bytes), then
-             ** must be corruption somewhere.  Or in the case of wal2 mode,
+               /* If the size of the final database is larger than the current
+               ** database plus the amount of data in the wal file, plus the
+               ** maximum size of the pending-byte page (65536 bytes), then
 -              ** must be corruption somewhere.  */
++              ** must be corruption somewhere.  Or in the case of wal2 mode,
 +            ** plus the amount of data in both wal files. */
-             rc = SQLITE_CORRUPT_BKPT;
-           }else{
-             sqlite3OsFileControlHint(pWal->pDbFd, SQLITE_FCNTL_SIZE_HINT,&nReq);
+               rc = SQLITE_CORRUPT_BKPT;
+             }else{
+               sqlite3OsFileControlHint(
+                   pWal->pDbFd, SQLITE_FCNTL_SIZE_HINT, &nReq);
+             }
            }
+   
          }
-       }
-       /* Iterate through the contents of the WAL, copying data to the db file */
-       while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){
-         i64 iOffset;
-         assert( bWal2==1 || walFramePgno(pWal, iFrame)==iDbpage );
-         assert( bWal2==0 || walFramePgno2(pWal, iCkpt, iFrame)==iDbpage );
+   
+         /* Iterate through the contents of the WAL, copying data to the 
+         ** db file */
+         while( rc==SQLITE_OK && 0==walIteratorNext(pIter, &iDbpage, &iFrame) ){
+           i64 iOffset;
 -          assert( walFramePgno(pWal, iFrame)==iDbpage );
 -          SEH_INJECT_FAULT;
++          assert( bWal2==1 || walFramePgno(pWal, iFrame)==iDbpage );
++          assert( bWal2==0 || walFramePgno2(pWal, iCkpt, iFrame)==iDbpage );
 +
 +        SEH_INJECT_FAULT;
-         if( AtomicLoad(&db->u1.isInterrupted) ){
-           rc = db->mallocFailed ? SQLITE_NOMEM_BKPT : SQLITE_INTERRUPT;
-           break;
-         }
-         if( iFrame<=nBackfill || iFrame>mxSafeFrame || iDbpage>mxPage ){
-           assert( bWal2==0 || iDbpage>mxPage );
-           continue;
+           if( AtomicLoad(&db->u1.isInterrupted) ){
+             rc = db->mallocFailed ? SQLITE_NOMEM_BKPT : SQLITE_INTERRUPT;
+             break;
+           }
+           if( iFrame<=nBackfill || iFrame>mxSafeFrame || iDbpage>mxPage ){
+             continue;
+           }
+           iOffset = walFrameOffset(iFrame, szPage) + WAL_FRAME_HDRSIZE;
+           /* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL file */
 -          rc = sqlite3OsRead(pWal->pWalFd, zBuf, szPage, iOffset);
++          rc = sqlite3OsRead(pWalFd, zBuf, szPage, iOffset);
+           if( rc!=SQLITE_OK ) break;
+           iOffset = (iDbpage-1)*(i64)szPage;
+           testcase( IS_BIG_INT(iOffset) );
+           rc = sqlite3OsWrite(pWal->pDbFd, zBuf, szPage, iOffset);
+           if( rc!=SQLITE_OK ) break;
          }
-         iOffset = walFrameOffset(iFrame, szPage) + WAL_FRAME_HDRSIZE;
-         WALTRACE(("WAL%p: checkpoint frame %d of wal %d to db page %d\n",
-               pWal, (int)iFrame, iCkpt, (int)iDbpage
-         ));
-         /* testcase( IS_BIG_INT(iOffset) ); // requires a 4GiB WAL file */
-         rc = sqlite3OsRead(pWalFd, zBuf, szPage, iOffset);
-         if( rc!=SQLITE_OK ) break;
-         iOffset = (iDbpage-1)*(i64)szPage;
-         testcase( IS_BIG_INT(iOffset) );
-         rc = sqlite3OsWrite(pWal->pDbFd, zBuf, szPage, iOffset);
-         if( rc!=SQLITE_OK ) break;
-       }
-       sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_CKPT_DONE, 0);
-       /* If work was actually accomplished, truncate the db file, sync the wal
-       ** file and set WalCkptInfo.nBackfill to indicate so. */
-       if( rc==SQLITE_OK && (bWal2 || mxSafeFrame==walIndexHdr(pWal)->mxFrame) ){
-         if( !bWal2 ){
-           i64 szDb = pWal->hdr.nPage*(i64)szPage;
-           testcase( IS_BIG_INT(szDb) );
-           rc = sqlite3OsTruncate(pWal->pDbFd, szDb);
+         sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_CKPT_DONE, 0);
+   
 -        /* If work was actually accomplished... */
 -        if( rc==SQLITE_OK ){
 -          if( mxSafeFrame==walIndexHdr(pWal)->mxFrame ){
++        /* If work was actually accomplished, truncate the db file, sync the wal
++        ** file and set WalCkptInfo.nBackfill to indicate so. */
++        if( rc==SQLITE_OK 
++         && (bWal2 || mxSafeFrame==walIndexHdr(pWal)->mxFrame) 
++        ){
++          if( !bWal2 ){
+             i64 szDb = pWal->hdr.nPage*(i64)szPage;
+             testcase( IS_BIG_INT(szDb) );
+             rc = sqlite3OsTruncate(pWal->pDbFd, szDb);
 -            if( rc==SQLITE_OK ){
 -              rc = sqlite3OsSync(pWal->pDbFd, CKPT_SYNC_FLAGS(sync_flags));
 -            }
++          }
++          if( rc==SQLITE_OK ){
++            rc = sqlite3OsSync(pWal->pDbFd, CKPT_SYNC_FLAGS(sync_flags));
+           }
+           if( rc==SQLITE_OK ){
+             AtomicStore(&pInfo->nBackfill, mxSafeFrame); SEH_INJECT_FAULT;
+           }
          }
-           rc = sqlite3OsSync(pWal->pDbFd, CKPT_SYNC_FLAGS(sync_flags));
 +        if( rc==SQLITE_OK ){
-       }
-       if( rc==SQLITE_OK ){
-         AtomicStore(&pInfo->nBackfill, (bWal2 ? 1 : mxSafeFrame));
-         SEH_INJECT_FAULT;
++          AtomicStore(&pInfo->nBackfill, (bWal2 ? 1 : mxSafeFrame));
++          SEH_INJECT_FAULT;
 +        }
++
        }
  
        /* Release the reader lock held while backfilling */
@@@ -5210,12 -4376,11 +5230,13 @@@ int sqlite3WalCheckpoint
          sqlite3OsUnfetch(pWal->pDbFd, 0, 0);
        }
      }
-   
      /* Copy data from the log to the database file. */
      if( rc==SQLITE_OK ){
 -      if( pWal->hdr.mxFrame && walPagesize(pWal)!=nBuf ){
+       sqlite3FaultSim(660);
 +      if( (walPagesize(pWal)!=nBuf) 
 +       && ((pWal->hdr.mxFrame2 & 0x7FFFFFFF) || pWal->hdr.mxFrame)
 +      ){
          rc = SQLITE_CORRUPT_BKPT;
        }else if( eMode2!=SQLITE_CHECKPOINT_NOOP ){
          rc = walCheckpoint(pWal, db, eMode2, xBusy2, pBusyArg, sync_flags,zBuf);