diff --git a/ftparchive/cachedb.cc b/ftparchive/cachedb.cc index 12eac20..cc0faee 100644 --- a/ftparchive/cachedb.cc +++ b/ftparchive/cachedb.cc @@ -99,7 +99,7 @@ bool CacheDB::ReadyDB(std::string const &DB) return _error->Error(_("Unable to open DB file %s: %s"),DB.c_str(), db_strerror(err)); } } - + DBFile = DB; DBLoaded = true; return true; @@ -198,19 +198,26 @@ bool CacheDB::GetCurStat() if (DBLoaded) { - /* First see if there is anything about it - in the database */ - - /* Get the flags (and mtime) */ + // do a first query to just get the size of the data on disk InitQueryStats(); - // Ensure alignment of the returned structure Data.data = &CurStat; - Data.ulen = sizeof(CurStat); Data.flags = DB_DBT_USERMEM; + Data.ulen = 0; + Get(); + // if the StatStore size on disk and our struct size disagree, + // consider the record invalid (LP: #1274466), see also cachedb.h + if(Data.size != sizeof(CurStat)) + { + CurStat.Flags = 0; + return true; + } + + // if the data size matches, do the real query + Data.ulen = sizeof(CurStat); if (Get() == false) { CurStat.Flags = 0; - } + } CurStat.Flags = ntohl(CurStat.Flags); CurStat.FileSize = ntohl(CurStat.FileSize); } diff --git a/ftparchive/cachedb.h b/ftparchive/cachedb.h index edb8594..8892c32 100644 --- a/ftparchive/cachedb.h +++ b/ftparchive/cachedb.h @@ -101,6 +101,12 @@ class CacheDB FlSHA512=(1<<6), FlSource=(1<<7), }; + // WARNING: this struct is read/written to the DB so do not change the + // layout of the fields (see lp #1274466) + // + // As a precaution we always we always re-create the record + // if the size changes. this shouldn't be needed if we only + // append to the struct and use the appropriate flags struct StatStore { uint32_t Flags;