]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Make the shell .recover command and the dbdata.c module more robust in the face of...
authordan <Dan Kennedy>
Wed, 26 Oct 2022 18:04:34 +0000 (18:04 +0000)
committerdan <Dan Kennedy>
Wed, 26 Oct 2022 18:04:34 +0000 (18:04 +0000)
FossilOrigin-Name: 4eef562a00ae988f2426c9af51f4165c0e4cbccd601061664a0c54c19b9cc70f

ext/misc/dbdata.c
manifest
manifest.uuid

index 7405e7c8909c6c043a8633d7fa856c3cd18a3391..32d529bb41bd26f9fbab475ba8977e7c5ad5e504 100644 (file)
@@ -358,17 +358,30 @@ static int dbdataLoadPage(
 ** Read a varint.  Put the value in *pVal and return the number of bytes.
 */
 static int dbdataGetVarint(const u8 *z, sqlite3_int64 *pVal){
-  sqlite3_int64 v = 0;
+  sqlite3_uint64 u = 0;
   int i;
   for(i=0; i<8; i++){
-    v = (v<<7) + (z[i]&0x7f);
-    if( (z[i]&0x80)==0 ){ *pVal = v; return i+1; }
+    u = (u<<7) + (z[i]&0x7f);
+    if( (z[i]&0x80)==0 ){ *pVal = (sqlite3_int64)u; return i+1; }
   }
-  v = (v<<8) + (z[i]&0xff);
-  *pVal = v;
+  u = (u<<8) + (z[i]&0xff);
+  *pVal = (sqlite3_int64)u;
   return 9;
 }
 
+/*
+** Like dbdataGetVarint(), but set the output to 0 if it is less than 0
+** or greater than 0xFFFFFFFF. This can be used for all varints in an
+** SQLite database except for key values in intkey tables.
+*/
+static int dbdataGetVarintU32(const u8 *z, sqlite3_int64 *pVal){
+  sqlite3_int64 val;
+  int nRet = dbdataGetVarint(z, &val);
+  if( val<0 || val>0xFFFFFFFF ) val = 0;
+  *pVal = val;
+  return nRet;
+}
+
 /*
 ** Return the number of bytes of space used by an SQLite value of type
 ** eType.
@@ -540,7 +553,7 @@ static int dbdataNext(sqlite3_vtab_cursor *pCursor){
           if( bNextPage || iOff>pCsr->nPage ){
             bNextPage = 1;
           }else{
-            iOff += dbdataGetVarint(&pCsr->aPage[iOff], &nPayload);
+            iOff += dbdataGetVarintU32(&pCsr->aPage[iOff], &nPayload);
           }
     
           /* If this is a leaf intkey cell, load the rowid */
@@ -607,7 +620,7 @@ static int dbdataNext(sqlite3_vtab_cursor *pCursor){
               }
             }
     
-            iHdr = dbdataGetVarint(pCsr->pRec, &nHdr);
+            iHdr = dbdataGetVarintU32(pCsr->pRec, &nHdr);
             pCsr->nHdr = nHdr;
             pCsr->pHdrPtr = &pCsr->pRec[iHdr];
             pCsr->pPtr = &pCsr->pRec[pCsr->nHdr];
@@ -621,7 +634,7 @@ static int dbdataNext(sqlite3_vtab_cursor *pCursor){
           if( pCsr->pHdrPtr>&pCsr->pRec[pCsr->nRec] ){
             bNextPage = 1;
           }else{
-            pCsr->pHdrPtr += dbdataGetVarint(pCsr->pHdrPtr, &iType);
+            pCsr->pHdrPtr += dbdataGetVarintU32(pCsr->pHdrPtr, &iType);
             pCsr->pPtr += dbdataValueBytes(iType);
           }
         }
@@ -778,7 +791,7 @@ static int dbdataColumn(
           sqlite3_result_int64(ctx, pCsr->iIntkey);
         }else{
           sqlite3_int64 iType;
-          dbdataGetVarint(pCsr->pHdrPtr, &iType);
+          dbdataGetVarintU32(pCsr->pHdrPtr, &iType);
           dbdataValue(
               ctx, iType, pCsr->pPtr, &pCsr->pRec[pCsr->nRec] - pCsr->pPtr
           );
index 711609b28853292ac3fe60ed23b681498a1934d1..7edad4429da231a9ba89562e2014d103a5c77d3c 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Correct\smisuse\sof\slocalhost-mode-only\ssymbol\sS\sin\sfiddle-worker.js,\swhich\sshould\sfix\sthe\soutage\sreported\sin\s[forum:67d985ac0bbe407f|forum\spost\s67d985ac0bbe407f].
-D 2022-10-26T15:40:17.652
+C Make\sthe\sshell\s.recover\scommand\sand\sthe\sdbdata.c\smodule\smore\srobust\sin\sthe\sface\sof\scorrupted\sdatabases.
+D 2022-10-26T18:04:34.995
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -298,7 +298,7 @@ F ext/misc/closure.c dbfd8543b2a017ae6b1a5843986b22ddf99ff126ec9634a2f4047cd14c8
 F ext/misc/completion.c 6dafd7f4348eecc7be9e920d4b419d1fb2af75d938cd9c59a20cfe8beb2f22b9
 F ext/misc/compress.c 3354c77a7c8e86e07d849916000cdac451ed96500bfb5bd83b20eb61eee012c9
 F ext/misc/csv.c ca8d6dafc5469639de81937cb66ae2e6b358542aba94c4f791910d355a8e7f73
-F ext/misc/dbdata.c e316fba936571584e55abd5b974a32a191727a6b746053a0c9d439bd2cf93940
+F ext/misc/dbdata.c 8caece471d25790456bff52043592369f367cd8f41bcb55a2f6540a2c062c57a
 F ext/misc/dbdump.c b8592f6f2da292c62991a13864a60d6c573c47a9cc58362131b9e6a64f823e01
 F ext/misc/decimal.c 09f967dcf4a1ee35a76309829308ec278d3648168733f4a1147820e11ebefd12
 F ext/misc/eval.c 04bc9aada78c888394204b4ed996ab834b99726fb59603b0ee3ed6e049755dc1
@@ -2037,8 +2037,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 6efa0bae1678bf719a0693feeceb4c1e252fc86502bee9ee2a6d8af9a91d9b20
-R 42b8c73d0292f252fc1b26ba498e8eed
-U stephan
-Z 171dbba4f5a911c6906efc53820d42f2
+P 3b5aa50c223ac35c7d73e4629420a01408cd74d19ae5b887f91b7a657d91e026
+R 35ce71983125759a6aec05074aeb42bb
+U dan
+Z abadf61b49ea483e6a667d1435917fe4
 # Remove this line to create a well-formed Fossil manifest.
index c4408a562d6c3de522e7f2be68030b549813a2f4..a88c2839d9402083210e7214c2414e1e2d38b045 100644 (file)
@@ -1 +1 @@
-3b5aa50c223ac35c7d73e4629420a01408cd74d19ae5b887f91b7a657d91e026
\ No newline at end of file
+4eef562a00ae988f2426c9af51f4165c0e4cbccd601061664a0c54c19b9cc70f
\ No newline at end of file