SQLite

Check-in [e8bcdf938e]
Login

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

Overview
Comment:Fix a problem in btree.c that could cause a crash following an OOM. Also various test script problems.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | two-mappings
Files: files | file ages | folders
SHA1: e8bcdf938eee2c307c24d60d0295e5529291373b
User & Date: dan 2013-03-29 18:52:56.780
Context
2013-03-29
19:38
Further fixes for test scripts. (check-in: 23ffa4f9fb user: dan tags: two-mappings)
18:52
Fix a problem in btree.c that could cause a crash following an OOM. Also various test script problems. (check-in: e8bcdf938e user: dan tags: two-mappings)
11:24
Avoid assuming the page-size is 4096 bytes in os_unix.c. (check-in: 3b7ec8d79e user: dan tags: two-mappings)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/btree.c.
2592
2593
2594
2595
2596
2597
2598
2599

2600
2601
2602
2603
2604

2605
2606
2607
2608
2609
2610
2611

  for(pCsr=pBt->pCursor; pCsr && rc==SQLITE_OK; pCsr=pCsr->pNext){
    if( pCsr->iPage>=0 ){
      MemPage *pPg = pCsr->apPage[0];
      if( pPg && pPg->pDbPage->flags & PGHDR_MMAP ){
        MemPage *pNew = 0;
        rc = getAndInitPage(pBt, pPg->pgno, &pNew, 0);
        if( rc==SQLITE_OK && pCsr->iPage==0 ){

          pCsr->info.pCell = pNew->aData + (pCsr->info.pCell - pPg->aData);
        }
        pCsr->apPage[0] = pNew;
        releasePage(pPg);
        if( rc!=SQLITE_OK ) return rc;

      }
    }
  }

  return rc;
}








|
>
|
|
|
|
<
>







2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604

2605
2606
2607
2608
2609
2610
2611
2612

  for(pCsr=pBt->pCursor; pCsr && rc==SQLITE_OK; pCsr=pCsr->pNext){
    if( pCsr->iPage>=0 ){
      MemPage *pPg = pCsr->apPage[0];
      if( pPg && pPg->pDbPage->flags & PGHDR_MMAP ){
        MemPage *pNew = 0;
        rc = getAndInitPage(pBt, pPg->pgno, &pNew, 0);
        if( rc==SQLITE_OK ){
          if( pCsr->iPage==0 ){
            pCsr->info.pCell = pNew->aData + (pCsr->info.pCell - pPg->aData);
          }
          pCsr->apPage[0] = pNew;
          releasePage(pPg);

        }
      }
    }
  }

  return rc;
}

Changes to src/os_unix.c.
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
      }
#if HAVE_MREMAP
      /* If we have an mremap() call, resize the existing mapping. */
      else{
        unixMapping *pMap = &pFd->aMmap[0];
        pNew = osMremap(
            pMap->pMapRegion, pMap->mmapOrigsize, nMap, MREMAP_MAYMOVE
            );
        if( pNew==MAP_FAILED ){
          return SQLITE_IOERR_MMAP;
        }
        pFd->aMmap[0].pMapRegion = pNew;
        pFd->aMmap[0].mmapSize = nMap;
        pFd->aMmap[0].mmapOrigsize = nMap;
      }







|







4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
      }
#if HAVE_MREMAP
      /* If we have an mremap() call, resize the existing mapping. */
      else{
        unixMapping *pMap = &pFd->aMmap[0];
        pNew = osMremap(
            pMap->pMapRegion, pMap->mmapOrigsize, nMap, MREMAP_MAYMOVE
        );
        if( pNew==MAP_FAILED ){
          return SQLITE_IOERR_MMAP;
        }
        pFd->aMmap[0].pMapRegion = pNew;
        pFd->aMmap[0].mmapSize = nMap;
        pFd->aMmap[0].mmapOrigsize = nMap;
      }
Changes to test/mallocH.test.
58
59
60
61
62
63
64

65
66
67
68
69
70
71
     EXPLAIN QUERY PLAN SELECT * FROM abc AS t2 WHERE rowid=1;
  }
}

# Malloc failure during integrity_check pragma.
#
do_malloc_test mallocH-5 -sqlprep {

   CREATE TABLE t1(a PRIMARY KEY, b UNIQUE);
   CREATE TABLE t2(x,y);
   INSERT INTO t1 VALUES(1,2);
   INSERT INTO t2 SELECT * FROM t1;
} -sqlbody {
   PRAGMA integrity_check;
}







>







58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
     EXPLAIN QUERY PLAN SELECT * FROM abc AS t2 WHERE rowid=1;
  }
}

# Malloc failure during integrity_check pragma.
#
do_malloc_test mallocH-5 -sqlprep {
   PRAGMA mmap_limit = 0;
   CREATE TABLE t1(a PRIMARY KEY, b UNIQUE);
   CREATE TABLE t2(x,y);
   INSERT INTO t1 VALUES(1,2);
   INSERT INTO t2 SELECT * FROM t1;
} -sqlbody {
   PRAGMA integrity_check;
}
Changes to test/pagerfault.test.
1197
1198
1199
1200
1201
1202
1203

1204
1205
1206

1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
  }
} -test {
  faultsim_test_result {0 {}}

  set contents [db eval {SELECT * FROM t1}]
  if {$contents != "1 2"} { error "Bad database contents ($contents)" }


  set sz [file size test.db]
  if {$testrc!=0 && $sz!=1024*3 && $sz!=4096*3} { 
    error "Expected file size to be 3072 or 12288 bytes - actual size $sz bytes"

  }
  if {$testrc==0 && $sz!=4096*3} { 
    error "Expected file size to be 12288 bytes - actual size $sz bytes"
  }
} 

do_test pagerfault-27-pre {
  faultsim_delete_and_reopen
  db func a_string a_string
  execsql {







>
|
|
<
>

|
|







1197
1198
1199
1200
1201
1202
1203
1204
1205
1206

1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
  }
} -test {
  faultsim_test_result {0 {}}

  set contents [db eval {SELECT * FROM t1}]
  if {$contents != "1 2"} { error "Bad database contents ($contents)" }

  set nPg [file_page_count test.db]
  set pgsz [file_page_size test.db]
  if {$testrc!=0 && ($nPg!=3 || ($pgsz!=1024 && $pgsz!=4096))} {

    error "File should be 3 pages. Page size 1024 or 4096 bytes. Is $nPg/$pgsz."
  }
  if {$testrc==0 && ($nPg!=3 || $pgsz!=4096)} {
    error "File should be 3 pages. Page size 4096 bytes. Is $nPg/$pgsz."
  }
} 

do_test pagerfault-27-pre {
  faultsim_delete_and_reopen
  db func a_string a_string
  execsql {
Changes to test/tester.tcl.
1676
1677
1678
1679
1680
1681
1682












1683
1684
1685
1686
1687
1688
1689
}

# Return the number of pages in the database file $zFile, according to 
# the database header.
#
proc file_page_count {zFile} {
  set nPg [hexio_get_int [hexio_read $zFile 28 4]]












  return $nPg
}

# Return the page size of database file $zFile, according to the database 
# header.
#
proc file_page_size {zFile} {







>
>
>
>
>
>
>
>
>
>
>
>







1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
}

# Return the number of pages in the database file $zFile, according to 
# the database header.
#
proc file_page_count {zFile} {
  set nPg [hexio_get_int [hexio_read $zFile 28 4]]
  set pgsz [file_page_size $zFile]
  set filesz [file size $zFile]
  set syspgsz 4096

  # Check that the file size is consistent with the database page size,
  # the page count, and the system page size.
  if {($filesz < ($nPg * $pgsz))
   || ($filesz > (((($nPg * $pgsz)+$syspgsz-1) / $syspgsz) * $syspgsz))
  } {
    error "file_size=$filesz. page_count=$nPg. page_size=$pgsz."
  }

  return $nPg
}

# Return the page size of database file $zFile, according to the database 
# header.
#
proc file_page_size {zFile} {