/ Check-in [5180810e]
Login

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

Overview
Comment:Zero cached pages located beyond the end of the file before returning them. Ticket #2285. (CVS 3808)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:5180810eeaa3dfe3d934af0732a920ae117ec69f
User & Date: danielk1977 2007-04-05 05:46:14
Context
2007-04-05
08:40
Catch an IO error case introduced by (3808). (CVS 3809) check-in: 383a08e2 user: danielk1977 tags: trunk
05:46
Zero cached pages located beyond the end of the file before returning them. Ticket #2285. (CVS 3808) check-in: 5180810e user: danielk1977 tags: trunk
2007-04-04
01:27
Test coverage improvements. (CVS 3807) check-in: 25f49acc user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pager.c.

    14     14   ** The pager is used to access a database disk file.  It implements
    15     15   ** atomic commit and rollback through the use of a journal file that
    16     16   ** is separate from the database file.  The pager also implements file
    17     17   ** locking to prevent two processes from writing the same database
    18     18   ** file simultaneously, or one process from reading the database while
    19     19   ** another is writing.
    20     20   **
    21         -** @(#) $Id: pager.c,v 1.316 2007/04/02 11:22:22 drh Exp $
           21  +** @(#) $Id: pager.c,v 1.317 2007/04/05 05:46:14 danielk1977 Exp $
    22     22   */
    23     23   #ifndef SQLITE_OMIT_DISKIO
    24     24   #include "sqliteInt.h"
    25     25   #include "os.h"
    26     26   #include "pager.h"
    27     27   #include <assert.h>
    28     28   #include <string.h>
................................................................................
  3024   3024   
  3025   3025   #ifdef SQLITE_CHECK_PAGES
  3026   3026       pPg->pageHash = pager_pagehash(pPg);
  3027   3027   #endif
  3028   3028     }else{
  3029   3029       /* The requested page is in the page cache. */
  3030   3030       assert(pPager->nRef>0 || pgno==1);
         3031  +    if( pgno>sqlite3PagerPagecount(pPager) ){
         3032  +      /* This can happen after a truncation in exclusive mode. The pager
         3033  +      ** cache contains pages that are located after the end of the 
         3034  +      ** database file. Zero such pages before returning. Not doing this 
         3035  +      ** was causing the problem reported in ticket #2285.
         3036  +      */
         3037  +      memset(PGHDR_TO_DATA(pPg), 0, pPager->pageSize);
         3038  +    }
  3031   3039       TEST_INCR(pPager->nHit);
  3032   3040       page_ref(pPg);
  3033   3041     }
  3034   3042     *ppPage = pPg;
  3035   3043     return SQLITE_OK;
  3036   3044   }
  3037   3045   

Added test/tkt2285.test.

            1  +# 2005 September 17
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +# This file implements regression tests for SQLite library. Specifically.
           12  +# it contains tests to verify that ticket #2285 has been fixed.  
           13  +#
           14  +# $Id: tkt2285.test,v 1.1 2007/04/05 05:46:14 danielk1977 Exp $
           15  +
           16  +set testdir [file dirname $argv0]
           17  +source $testdir/tester.tcl
           18  +
           19  +ifcapable !tempdb {
           20  +  finish_test
           21  +  return
           22  +}
           23  +
           24  +do_test tkt2285-1.1 {
           25  +  execsql {
           26  +    PRAGMA locking_mode = EXCLUSIVE;
           27  +  }
           28  +  execsql {
           29  +    BEGIN;
           30  +    CREATE TABLE abc(a, b, c);
           31  +    ROLLBACK;
           32  +  }
           33  +} {}
           34  +
           35  +do_test tkt2285-1.2 {
           36  +  execsql {
           37  +    SELECT * FROM sqlite_master;
           38  +  }
           39  +} {}
           40  +
           41  +ifcapable tempdb {
           42  +  do_test tkt2285-2.1 {
           43  +    execsql {
           44  +      BEGIN;
           45  +      CREATE TEMP TABLE abc(a, b, c);
           46  +      ROLLBACK;
           47  +    }
           48  +  } {}
           49  +  do_test tkt2285-2.2 {
           50  +    execsql {
           51  +      SELECT * FROM sqlite_temp_master;
           52  +    }
           53  +  } {}
           54  +}
           55  +
           56  +finish_test
           57  +