SQLite Forum

Interpreting output from showdb
Login

Interpreting output from showdb

(1) By Jonas Bülow (jbulow) on 2021-06-08 11:11:37 [link] [source]

Hi,

I'm analyzing a corrupt SQLite database file using the showdb tool. I'm not sure how to interpret the following output:

ERROR: page 641 used multiple times:
ERROR:    previous: overflow 1 from cell 0 of page 128
ERROR:    current:  overflow 1 from cell 0 of page 128
ERROR: page 604 used multiple times:
ERROR:    previous: overflow 1 from cell 1 of page 128
ERROR:    current:  overflow 1 from cell 1 of page 128
ERROR: page 667 used multiple times:
ERROR:    previous: overflow 1 from cell 2 of page 128
ERROR:    current:  overflow 1 from cell 2 of page 128
ERROR: page 555 used multiple times:
ERROR:    previous: overflow 1 from cell 3 of page 128
ERROR:    current:  overflow 1 from cell 3 of page 128
ERROR: page 172 used multiple times:
ERROR:    previous: overflow 1 from cell 4 of page 128
ERROR:    current:  overflow 1 from cell 4 of page 128
ERROR: page 204 used multiple times:
ERROR:    previous: overflow 1 from cell 5 of page 128
ERROR:    current:  overflow 1 from cell 5 of page 128
ERROR: page 592 used multiple times:
ERROR:    previous: overflow 1 from cell 6 of page 128
ERROR:    current:  overflow 1 from cell 6 of page 128

Also, I had to apply the following patch to avoid crashing on double free when running showdb:

>fossil diff
Index: tool/showdb.c
==================================================================
--- tool/showdb.c
+++ tool/showdb.c
@@ -793,10 +793,12 @@
   if( zPageUse[pgno]!=0 ){
     printf("ERROR: page %d used multiple times:\n", pgno);
     printf("ERROR:    previous: %s\n", zPageUse[pgno]);
     printf("ERROR:    current:  %s\n", zMsg);
     sqlite3_free(zPageUse[pgno]);
+    zPageUse[pgno] = 0;
   }
   zPageUse[pgno] = zMsg;
 }

(2) By Richard Hipp (drh) on 2021-06-08 12:18:14 in reply to 1 [link] [source]

I'm guessing that you are not showing us the complete showdb output, but just the part that has you confused. I'm guessing that there was a prior entry about "page 128 used multiple times". Probably page 128 appears twice in the same btree, or in two separate btrees. Overflow entries on that page are thus used twice.

Your patch appears to be a no-op. You are setting "zPageUse[pgno] = 0;" immediately prior to "zPageUse[pgno] = zMsg;". I would expect that an optimizing C compiler would recognize that the new statement does nothing and hence omit it from the generated code. Am I missing something?

(3) By Jonas Bülow (jbulow) on 2021-06-08 12:45:47 in reply to 2 [source]

You are right. The complete start of the output is:

Pagesize: 512                                                                                                                                                                                                                                                                                                               
Available pages: 1..184320                                                                                                                                                                                                                                                                                                  
ERROR: page 5 used multiple times:                                                                                                                                                                                                                                                                                          
ERROR:    previous: overflow 1 from cell 1 of page 14                                                                                                                                                                                                                                                                       
ERROR:    current:  root corrupt node [t9fef1aed_2Dfc51_2D4f99_2D925f_2D675dd2a8c7bf], 99 rows                                                                                                                                                                                                                              
ERROR: page 7 used multiple times:                                                                                                                                                                                                                                                                                          
ERROR:    previous: overflow 1 from cell 2 of page 14                                                                                                                                                                                                                                                                       
ERROR:    current:  root corrupt node [t418cb1c8_2D5bd5_2D4f9c_2Da063_2D2a3bcdd8deb3], 50 rows                                                                                                                                                                                                                              
ERROR: page 9 used multiple times:                                                                                                                                                                                                                                                                                          
ERROR:    previous: overflow 1 from cell 3 of page 14                                                                                                                                                                                                                                                                       
ERROR:    current:  root corrupt node [t9a59e751_2D18eb_2D41e3_2Da2ca_2D55cf3c6fa1b8], 48 rows                                                                                                                                                                                                                              
ERROR: page 79 used multiple times:                                                                                                                                                                                                                                                                                         
ERROR:    previous: leaf of table [d1dfc7c0_2Dac38_2D4899_2Db1b0_2Dd0780554c9b7], child 0 of page 3142, 6 rows                                                                                                                                                                                                              
ERROR:    current:  root leaf of table [t063dd2e7_2D97fa_2D4eb1_2D92bb_2D44d4230b4227], 6 rows                                                                                                                                                                                                                              
ERROR: page 62 used multiple times:                                                                                                                                                                                                                                                                                         
ERROR:    previous: root leaf of table [t7c30a8b1_2D7b74_2D442e_2Dadc9_2Dd037ae25d1e4], 6 rows                                                                                                                                                                                                                              
ERROR:    current:  leaf of table [aad9a5bc_2D8e1e_2D4ec7_2Dbaf5_2D839e35e75613], child 0 of page 1004, 6 rows                                                                                                                                                                                                              
ERROR: page 122 used multiple times:                                                                                                                                                                                                                                                                                        
ERROR:    previous: leaf of table [d1dfc7c0_2Dac38_2D4899_2Db1b0_2Dd0780554c9b7], child 1 of page 3142, 9 rows                                                                                                                                                                                                              
ERROR:    current:  root leaf of table [d6aeb767_2D5334_2D4c8a_2D96f3_2D028dddd3ca85], 9 rows                                                                                                                                                                                                                               
ERROR: page 128 used multiple times:                                                                                                                                                                                                                                                                                        
ERROR:    previous: leaf of table [sqlite_schema], child 1 of page 146247, 9 rows                                                                                                                                                                                                                                           
ERROR:    current:  root leaf of table [t244f7970_2Dfcdc_2D4926_2D9e33_2D5538eff75ec0], 9 rows                                                                                                                                                                                                                              
ERROR: page 641 used multiple times:                                                                                                                                                                                                                                                                                        
ERROR:    previous: overflow 1 from cell 0 of page 128                                                                                                                                                                                                                                                                      
ERROR:    current:  overflow 1 from cell 0 of page 128                                                                                                                                                                                                                                                                      
ERROR: page 604 used multiple times:                                                                                                                                                                                                                                                                                        
ERROR:    previous: overflow 1 from cell 1 of page 128                                                                                                                                                                                                                                                                      
ERROR:    current:  overflow 1 from cell 1 of page 128                                                                                                                                                                                                                                                                      
ERROR: page 667 used multiple times:                                                                                                                                                                                                                                                                                        
ERROR:    previous: overflow 1 from cell 2 of page 128                                                                                                                                                                                                                                                                      
ERROR:    current:  overflow 1 from cell 2 of page 128                            

and then it fails a few lines later with:

   58: root leaf of table [adf68a99_2D066f_2D4611_2D928b_2D2ad729a26ee3], 7 rows
   59: leaf of table [], child 0 of page -1, 10 rows
   60: root leaf of table [cd54870a_2Dd584_2D49bd_2Da1b3_2D421d4003a71f], 9 rows
   61: leaf of table [], child 0 of page -1, 6 rows
   62: leaf of table [aad9a5bc_2D8e1e_2D4ec7_2Dbaf5_2D839e35e75613], child 0 of page 1004, 6 rows
   63: leaf of table [], child 0 of page -1, 6 rows
   64: leaf of table [aad9a5bc_2D8e1e_2D4ec7_2Dbaf5_2D839e35e75613], child 1 of page 1004, 9 rows
   65: root leaf of table [t1352f6ef_2Df84e_2D4f52_2D9da7_2D076d1e471481], 11 rows
   66: leaf of table [], child 0 of page -1, 8 rows
   67: root leaf of table [ef0769bf_2Db2e3_2D43be_2D830d_2Da41ba7a4aa7c], 14 rows
   68: leaf of table [], child 0 of page -1, 11 rows
   69: root leaf of table [t32322c96_2D58ba_2D46f8_2Dab16_2D6575d90679a8], 11 rows
   70: leaf of table [], child 0 of page -1, 9 rows
   71: root leaf of table [t830d0904_2D2e2b_2D4782_2Dab02_2D2696e1354f16], 11 rows
ERROR: page 58 used multiple times:
ERROR:    previous: root leaf of table [adf68a99_2D066f_2D4611_2D928b_2D2ad729a26ee3], 7 rows
ERROR:    current:  leaf of table [], child 0 of page 2432, 7 rows
double free or corruption (!prev)

And the temporary patch I used to get the program run without any "double free" is:

Index: tool/showdb.c
==================================================================
--- tool/showdb.c
+++ tool/showdb.c
@@ -792,11 +792,10 @@
   }
   if( zPageUse[pgno]!=0 ){
     printf("ERROR: page %d used multiple times:\n", pgno);
     printf("ERROR:    previous: %s\n", zPageUse[pgno]);
     printf("ERROR:    current:  %s\n", zMsg);
-    sqlite3_free(zPageUse[pgno]);
   }
   zPageUse[pgno] = zMsg;
 }

(4) By Richard Hipp (drh) on 2021-06-08 17:57:28 in reply to 3 [link] [source]

Please try the latest change to showdb.c and let me know if that clears your problem.

(5) By Jonas Bülow (jbulow) on 2021-06-09 06:18:34 in reply to 4 [link] [source]

Yes, the latest change in showdb.c fixed the double free problem.