/ Check-in [80e951fc]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add an extra test for database corruption to defragmentPage().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 80e951fce3e5aaa224c8dba6449832d2efabcdc24e86eb6b7833f85cf08ecc00
User & Date: dan 2019-03-21 21:18:36
Context
2019-03-22
11:38
Add the --limit N option to dbfuzz2. Set the default callback limit to 250K. check-in: b99f8512 user: drh tags: trunk
01:25
Support building the Tcl bindings DLL using MSVC. check-in: 908c4c89 user: mistachkin tags: msvcTcl
2019-03-21
21:18
Add an extra test for database corruption to defragmentPage(). check-in: 80e951fc user: dan tags: trunk
2019-03-20
18:22
In the CLI, give better error messages if something goes wrong with the ".dbinfo" command. check-in: 3649a77b user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

  1451   1451           }
  1452   1452           if( iFree2 ){
  1453   1453             if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_PAGE(pPage);
  1454   1454             sz2 = get2byte(&data[iFree2+2]);
  1455   1455             if( iFree2+sz2 > usableSize ) return SQLITE_CORRUPT_PAGE(pPage);
  1456   1456             memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz));
  1457   1457             sz += sz2;
         1458  +        }else if( iFree+sz>usableSize ){
         1459  +          return SQLITE_CORRUPT_PAGE(pPage);
  1458   1460           }
         1461  +
  1459   1462           cbrk = top+sz;
  1460   1463           assert( cbrk+(iFree-top) <= usableSize );
  1461   1464           memmove(&data[cbrk], &data[top], iFree-top);
  1462   1465           for(pAddr=&data[cellOffset]; pAddr<pEnd; pAddr+=2){
  1463   1466             pc = get2byte(pAddr);
  1464   1467             if( pc<iFree ){ put2byte(pAddr, pc+sz); }
  1465   1468             else if( pc<iFree2 ){ put2byte(pAddr, pc+sz2); }

Changes to test/corruptL.test.

   722    722   |      0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00   ................
   723    723   | end crash-8391315d75edff.db
   724    724   }]} {}
   725    725   
   726    726   do_catchsql_test 7.1 {
   727    727     SELECT * FROM sqlite_master;
   728    728   } {1 {malformed database schema (t1x1) - invalid rootpage}}
          729  +
          730  +#-------------------------------------------------------------------------
          731  +reset_db
          732  +do_test 8.0 {
          733  +  sqlite3 db {}
          734  +  db deserialize [decode_hexdb {
          735  +| size 2048 pagesize 512 filename a.db
          736  +| page 1 offset 0
          737  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
          738  +|     16: 02 00 01 01 00 40 20 20 ff ff 00 0c 00 00 00 07   .....@  ........
          739  +|     32: 0b 00 00 00 00 00 00 00 00 00 00 08 9c 00 00 04   ................
          740  +|     48: 00 00 00 e0 09 00 00 01 00 00 00 01 00 00 00 00   ................
          741  +|     64: 00 00 00 00 f2 ff 00 00 00 00 00 00 00 00 00 00   ................
          742  +|     80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0c   ................
          743  +|     96: 00 2e 2c 50 0d 00 00 00 06 01 06 00 01 da 01 b0   ..,P............
          744  +|    112: 05 56 01 86 01 2a 01 06 00 00 00 00 00 06 00 00   .V...*..........
          745  +|    128: 00 ff 00 00 ff ff ff e1 00 00 00 00 00 00 00 00   ................
          746  +|    144: 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00   ................
          747  +|    160: 00 00 00 00 00 00 00 00 f2 00 00 00 00 00 00 00   ................
          748  +|    176: 00 00 f9 ff ff ff ff ff ff ff 00 00 00 5f 00 fb   ............._..
          749  +|    192: 00 00 00 00 00 00 00 00 00 e1 ff 00 00 00 00 00   ................
          750  +|    208: 00 00 10 00 00 00 00 00 1e 00 00 00 fe 00 00 00   ................
          751  +|    224: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ca 00   ................
          752  +|    240: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 35   ...............5
          753  +|    256: 00 00 00 00 ef ff 22 07 06 17 11 11 01 30 39 38   .............098
          754  +|    272: 62 6c 65 74 38 38 74 04 43 52 45 41 54 45 20 54   blet88t.CREATE T
          755  +|    288: 41 42 4c 45 20 74 34 28 87 29 2a 06 06 17 13 11   ABLE t4(.)*.....
          756  +|    304: 01 3f 69 4f 64 65 78 74 33 78 74 40 05 43 52 45   .?iOdext3xt@.CRE
          757  +|    320: 41 54 45 20 49 6e 44 45 58 20 74 33 78 20 4f 4e   ATE InDEX t3x ON
          758  +|    336: 20 74 33 28 78 29 2e 04 06 17 15 11 01 45 69 6e    t3(x).......Ein
          759  +|    352: 00 04 00 00 34 63 64 74 3d 05 43 52 45 41 54 45   ....4cdt=.CREATE
          760  +|    368: 20 49 4e 44 45 58 20 63 74 64 32 20 4f 4e 20 74    INDEX ctd2 ON t
          761  +|    384: 32 28 0a 0c 44 29 28 05 06 17 11 11 01 3d 74 6c   2(..D)(......=tl
          762  +|    400: 62 61 d4 65 33 74 33 04 43 52 45 41 54 45 20 54   ba.e3t3.CREATE T
          763  +|    416: 41 42 4c 45 20 74 33 28 63 2c 78 2c 65 2c 66 29   ABLE t3(c,x,e,f)
          764  +|    432: 28 02 06 17 11 11 01 3d 74 61 62 6c 65 74 32 74   (......=tablet2t
          765  +|    448: 32 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 74   2.CREATE TABLE t
          766  +|    464: 32 28 63 2c 64 2c 65 2c 66 29 24 01 06 17 11 11   2(c,d,e,f)$.....
          767  +|    480: 01 35 74 60 62 6c 65 74 31 74 31 02 43 52 45 41   .5t`blet1t1.CREA
          768  +|    496: 54 45 20 54 41 42 4c 45 20 74 30 28 61 2c 62 29   TE TABLE t0(a,b)
          769  +| page 2 offset 512
          770  +|      0: 0d 00 ff 11 04 01 cf 80 01 fa 01 09 00 de 01 cf   ................
          771  +|     16: 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00   ................
          772  +|     32: 00 00 08 00 00 00 00 00 00 11 00 00 00 00 00 13   ................
          773  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 e0 ff ff   ................
          774  +|     64: ff d2 ff ff ff 00 f8 ff ff ff 00 00 00 00 00 00   ................
          775  +|     80: 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
          776  +|     96: 00 00 00 00 ff de 00 00 00 00 00 00 00 00 00 00   ................
          777  +|    112: 00 00 00 00 00 00 00 00 00 00 00 00 00 40 00 00   .............@..
          778  +|    128: 2a 00 00 00 00 00 00 00 00 f7 00 00 00 00 00 00   *...............
          779  +|    144: 00 00 00 00 00 21 00 00 00 00 00 00 00 00 00 00   .....!..........
          780  +|    160: 01 64 00 00 00 00 04 80 ff ff ff 00 00 00 00 00   .d..............
          781  +|    176: 00 00 00 00 00 00 00 00 1f 00 00 00 00 00 00 00   ................
          782  +|    192: 00 00 40 00 00 00 00 00 00 00 00 00 00 00 00 00   ..@.............
          783  +|    208: b5 00 00 00 00 00 00 40 00 00 00 00 00 00 00 00   .......@........
          784  +|    224: 00 00 00 f6 00 ee ff ff ff 00 00 00 00 00 00 00   ................
          785  +|    272: f2 00 00 00 00 00 00 00 00 00 f9 ff ff ff ff ff   ................
          786  +|    288: ff ff 00 00 00 5f 00 fb 00 00 00 00 00 00 00 00   ....._..........
          787  +|    320: 1e 00 00 00 fe 00 00 00 00 00 00 00 00 00 00 00   ................
          788  +|    336: 00 00 00 00 00 00 ca 00 00 00 00 00 00 00 ff ec   ................
          789  +|    352: 00 00 00 00 00 00 00 32 00 00 00 00 ef ff 22 07   .......2........
          790  +|    368: 06 17 11 11 01 30 74 61 62 6c 65 74 38 38 74 04   .....0tablet88t.
          791  +|    384: 43 52 45 41 54 45 20 54 41 42 4c 45 20 8c cb d7   CREATE TABLE ...
          792  +|    400: 78 d6 d5 f9 f9 17 13 11 01 3f 69 4f 64 65 78 74   x........?iOdext
          793  +|    416: 33 78 74 33 05 43 52 45 41 54 45 26 49 6e 44 45   3xt3.CREATE&InDE
          794  +|    432: 58 20 74 33 78 00 00 00 00 00 00 00 00 00 00 00   X t3x...........
          795  +|    464: 00 00 00 00 00 13 76 65 6e 65 69 67 68 74 13 03   ......veneight..
          796  +|    480: 03 40 07 07 15 00 54 45 20 49 4e 44 45 58 20 74   .@....TE INDEX t
          797  +|    496: 31 63 64 20 4f 4e 20 74 ce d7 f5 f0 44 09 01 02   1cd ON t....D...
          798  +| page 3 offset 1024
          799  +|      0: 0d 00 00 00 48 01 54 00 01 f6 e2 ec 01 c5 01 aa   ....H.T.........
          800  +|     16: 30 34 28 87 29 32 06 f5 16 13 11 01 8e 61 24 64   04(.)2.......a$d
          801  +|     32: 65 78 74 37 78 1f 33 6d 6d 6d 6d 6d 00 00 04 06   ext7x.3mmmmm....
          802  +|     48: 6d 41 6d 6d 6e 6d 6d 00 00 02 00 6d 6d 6d 6d 6d   mAmmnmm....mmmmm
          803  +|     64: 15 11 01 45 45 45 45 45 45 45 45 45 45 45 45 45   ...EEEEEEEEEEEEE
          804  +|     80: 45 45 45 45 45 45 45 45 45 45 45 00 45 63 74 64   EEEEEEEEEEE.Ectd
          805  +|     96: 34 20 4f 4e 20 61 62 6c 5d 74 38 38 74 04 43 52   4 ON abl]t88t.CR
          806  +|    112: 45 41 54 45 20 54 41 42 4c 45 20 74 34 28 87 29   EATE TABLE t4(.)
          807  +|    128: 2a 06 06 13 13 01 00 00 00 4f 64 6e 78 74 33 44   *........Odnxt3D
          808  +|    144: 74 13 05 43 52 45 41 54 45 20 49 6e 44 45 00 00   t..CREATE InDE..
          809  +|    160: 00 00 00 00 00 00 00 f9 ff ff ff ff ff ff ff 00   ................
          810  +|    176: 00 00 5f 00 fb 00 00 2d 00 00 00 00 00 00 00 00   .._....-........
          811  +|    192: 00 00 00 00 00 00 00 00 00 00 00 00 00 1e 00 00   ................
          812  +|    208: 00 fe 00 00 00 00 17 15 11 01 45 69 6e 64 65 2e   ..........Einde.
          813  +|    224: 5b 38 63 64 74 3d 05 43 52 45 41 54 45 20 49 4e   [8cdt=.CREATE IN
          814  +|    240: 44 45 58 20 63 20 64 32 20 4f 4e 20 74 32 28 0a   DEX c d2 ON t2(.
          815  +|    256: 0c 44 32 05 00 10 00 00 11 11 3d 74 6c 62 61 d4   .D2.......=tlba.
          816  +|    272: 65 33 74 33 04 43 52 45 41 54 45 20 54 41 42 4c   e3t3.CREATE TABL
          817  +|    288: 45 20 74 36 ff ff 7f ff 43 52 45 41 54 45 20 49   E t6....CREATE I
          818  +|    304: 73 71 6c 69 74 65 5f 73 65 71 75 65 6e 63 65 28   sqlite_sequence(
          819  +|    320: 0a 0c 44 29 28 05 06 17 11 11 01 3d 74 6c 62 61   ..D)(......=tlba
          820  +|    336: 20 00 00 00 33 04 43 52 45 41 54 45 20 54 41 42    ...3.CREATE TAB
          821  +|    352: 4c 45 20 74 33 28 63 2c 78 2c 65 2c 66 29 28 02   LE t3(c,x,e,f)(.
          822  +|    368: 06 00 00 7f ff 40 41 54 45 20 49 6e 44 45 58 20   .....@ATE InDEX 
          823  +|    384: 74 33 78 20 4f 4e 20 74 31 28 78 29 2e 04 06 17   t3x ON t1(x)....
          824  +|    400: 15 11 01 45 69 6e 64 65 2e 74 34 63 64 74 3d 05   ...Einde.t4cdt=.
          825  +|    416: 00 00 00 00 00 00 00 00 00 00 00 4d 00 00 00 00   ...........M....
          826  +|    432: 01 00 00 00 00 00 00 05 00 00 10 00 00 00 00 00   ................
          827  +|    448: 00 01 00 00 00 00 01 00 00 00 00 07 40 14 00 00   ............@...
          828  +|    464: 00 00 21 00 40 18 00 00 00 00 00 00 40 1c 00 00   ..!.@.......@...
          829  +|    480: 00 00 ff ff ff 00 00 00 5f 00 fb 00 00 2d 00 00   ........_....-..
          830  +|    496: 00 00 00 1e 00 00 00 fe 00 00 64 00 00 ff fb 02   ..........d.....
          831  +| page 4 offset 1536
          832  +|      0: 0d 00 39 00 00 02 00 00 00 00 00 00 00 00 00 00   ..9.............
          833  +| end a.db
          834  +}]} {}
          835  +
          836  +
          837  +do_catchsql_test 8.1 {
          838  +  INSERT INTO t3 SELECT * FROM t2;
          839  +} {1 {database disk image is malformed}}
   729    840   
   730    841   finish_test