/ Changes On Branch robust-against-damaged-db
Login

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

Changes In Branch robust-against-damaged-db Excluding Merge-Ins

This is equivalent to a diff from 147a9429a5 to 585c94db09

2018-10-30
15:20
Improvements to the -fsanitize=fuzzer based database file fuzzer. (Cherrypick from the rubust-against-damaged-db branch.) (check-in: 3cc01a0eaf user: drh tags: trunk)
13:19
Enable sqlite3_deserialize() in the CLI. The --deserialize option associated with opening a new database cause the database file to be read into memory and accessed using the sqlite3_deserialize() API. This simplifies running tests on a database without risk of modifying the file on disk. (check-in: 5e0129ee9a user: drh tags: trunk)
00:06
Improvements to the -fsanitize=fuzzer based database file fuzzer. (Closed-Leaf check-in: 585c94db09 user: drh tags: robust-against-damaged-db)
00:06
In the VACUUM command, defer setting writable_schema until after it has been determined that the schema is not corrupt. (check-in: 3afec26014 user: drh tags: robust-against-damaged-db)
2018-10-29
21:01
Fix a potential assertion fault that can occur while trying to DROP a table from a corrupted database file. (check-in: 147a9429a5 user: drh tags: trunk)
18:33
Fix minor memory leak in the dbstat extension that can occur following an attempt to analyze a corrupt database file. (check-in: cb874fd873 user: drh tags: trunk)

Changes to src/vacuum.c.

160
161
162
163
164
165
166
167

168
169
170
171
172
173
174
160
161
162
163
164
165
166

167
168
169
170
171
172
173
174







-
+







  ** restored before returning. Then set the writable-schema flag, and
  ** disable CHECK and foreign key constraints.  */
  saved_flags = db->flags;
  saved_mDbFlags = db->mDbFlags;
  saved_nChange = db->nChange;
  saved_nTotalChange = db->nTotalChange;
  saved_mTrace = db->mTrace;
  db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks;
  db->flags |= SQLITE_IgnoreChecks;
  db->mDbFlags |= DBFLAG_PreferBuiltin | DBFLAG_Vacuum;
  db->flags &= ~(SQLITE_ForeignKeys | SQLITE_ReverseOrder | SQLITE_CountRows);
  db->mTrace = 0;

  zDbMain = db->aDb[iDb].zDbSName;
  pMain = db->aDb[iDb].pBt;
  isMemDb = sqlite3PagerIsMemdb(sqlite3BtreePager(pMain));
281
282
283
284
285
286
287

288
289
290
291
292
293
294
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295







+







  if( rc!=SQLITE_OK ) goto end_of_vacuum;

  /* Copy the triggers, views, and virtual tables from the main database
  ** over to the temporary database.  None of these objects has any
  ** associated storage, so all we have to do is copy their entries
  ** from the SQLITE_MASTER table.
  */
  db->flags |= SQLITE_WriteSchema;
  rc = execSqlF(db, pzErrMsg,
      "INSERT INTO vacuum_db.sqlite_master"
      " SELECT*FROM \"%w\".sqlite_master"
      " WHERE type IN('view','trigger')"
      " OR(type='table'AND rootpage=0)",
      zDbMain
  );

Changes to test/dbfuzz2.c.

74
75
76
77
78
79
80
81

82
83

84
85
86
87
88
89
90
91
92
93
94
95
96




97



98


99
100
101
102
103
104
105
74
75
76
77
78
79
80

81
82

83
84
85
86
87
88
89
90
91
92
93
94
95

96
97
98
99
100
101
102
103

104
105
106
107
108
109
110
111
112







-
+

-
+












-
+
+
+
+

+
+
+
-
+
+







  int rc;
  int i;

  if( eVerbosity>=1 ){
    printf("************** nByte=%d ***************\n", (int)nByte);
    fflush(stdout);
  }
  rc = sqlite3_open(":memory:", &db);
  rc = sqlite3_open(0, &db);
  if( rc ) return 1;
  a = sqlite3_malloc64(nByte);
  a = sqlite3_malloc64(nByte+1);
  if( a==0 ) return 1;
  memcpy(a, aData, nByte);
  sqlite3_deserialize(db, "main", a, nByte, nByte,
        SQLITE_DESERIALIZE_RESIZEABLE |
        SQLITE_DESERIALIZE_FREEONCLOSE);
  for(i=0; i<sizeof(azSql)/sizeof(azSql[0]); i++){
    if( eVerbosity>=1 ){
      printf("%s\n", azSql[i]);
      fflush(stdout);
    }
    sqlite3_exec(db, azSql[i], 0, 0, 0);
  }
  sqlite3_close(db);
  rc = sqlite3_close(db);
  if( rc!=SQLITE_OK ){
    fprintf(stdout, "sqlite3_close() returns %d\n", rc);
  }
  if( sqlite3_memory_used()!=0 ){
    int nAlloc = 0;
    int nNotUsed = 0;
    sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &nAlloc, &nNotUsed, 0);
    fprintf(stderr,"Memory leak: %lld bytes\n", sqlite3_memory_used());
    fprintf(stderr,"Memory leak: %lld bytes in %d allocations\n",
            sqlite3_memory_used(), nAlloc);
    exit(1);
  }
  return 0;
}

/* libFuzzer invokes this routine once when the executable starts, to
** process the command-line arguments.