Changeset 96007 in webkit


Ignore:
Timestamp:
Sep 26, 2011 3:22:23 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

IndexedDB: Null key path gets stored as empty string key path
https://bugs.webkit.org/show_bug.cgi?id=68726

Patch by Joshua Bell <jsbell@chromium.org> on 2011-09-26
Reviewed by Tony Chang.

Store additional flag to indicate if object store key path
is null vs. empty. Added additional runtime tests for integrity
of object store metadata.

  • storage/IDBLevelDBBackingStore.cpp:

(WebCore::checkObjectStoreAndMetaDataType):
(WebCore::IDBLevelDBBackingStore::getObjectStores):
(WebCore::IDBLevelDBBackingStore::createObjectStore):

  • storage/IDBLevelDBCoding.cpp:
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r96000 r96007  
     12011-09-26  Joshua Bell  <jsbell@chromium.org>
     2
     3        IndexedDB: Null key path gets stored as empty string key path
     4        https://bugs.webkit.org/show_bug.cgi?id=68726
     5
     6        Reviewed by Tony Chang.
     7
     8        Store additional flag to indicate if object store key path
     9        is null vs. empty. Added additional runtime tests for integrity
     10        of object store metadata.
     11
     12        * storage/IDBLevelDBBackingStore.cpp:
     13        (WebCore::checkObjectStoreAndMetaDataType):
     14        (WebCore::IDBLevelDBBackingStore::getObjectStores):
     15        (WebCore::IDBLevelDBBackingStore::createObjectStore):
     16        * storage/IDBLevelDBCoding.cpp:
     17
    1182011-09-26  John Bauman  <jbauman@chromium.org>
    219
  • trunk/Source/WebCore/storage/IDBLevelDBBackingStore.cpp

    r95901 r96007  
    213213}
    214214
     215static bool checkObjectStoreAndMetaDataType(const LevelDBIterator* it, const Vector<char>& stopKey, int64_t objectStoreId, int64_t metaDataType)
     216{
     217    if (!it->isValid() || compareKeys(it->key(), stopKey) >= 0)
     218        return false;
     219
     220    ObjectStoreMetaDataKey metaDataKey;
     221    const char* p = ObjectStoreMetaDataKey::decode(it->key().begin(), it->key().end(), &metaDataKey);
     222    ASSERT_UNUSED(p, p);
     223    if (metaDataKey.objectStoreId() != objectStoreId)
     224        return false;
     225    if (metaDataKey.metaDataType() != metaDataType)
     226        return false;
     227    return true;
     228}
     229
    215230void IDBLevelDBBackingStore::getObjectStores(int64_t databaseId, Vector<int64_t>& foundIds, Vector<String>& foundNames, Vector<String>& foundKeyPaths, Vector<bool>& foundAutoIncrementFlags)
    216231{
     
    219234
    220235    OwnPtr<LevelDBIterator> it = m_db->createIterator();
    221     for (it->seek(startKey); it->isValid() && compareKeys(it->key(), stopKey) < 0; it->next()) {
     236    it->seek(startKey);
     237    while (it->isValid() && compareKeys(it->key(), stopKey) < 0) {
    222238        const char *p = it->key().begin();
    223239        const char *limit = it->key().end();
     
    226242        p = ObjectStoreMetaDataKey::decode(p, limit, &metaDataKey);
    227243        ASSERT(p);
    228 
    229         int64_t objectStoreId = metaDataKey.objectStoreId();
    230 
    231         String objectStoreName = decodeString(it->value().begin(), it->value().end());
    232 
    233         it->next();
    234         if (!it->isValid()) {
     244        if (metaDataKey.metaDataType()) {
    235245            LOG_ERROR("Internal Indexed DB error.");
    236246            return;
    237247        }
    238         String keyPath = decodeString(it->value().begin(), it->value().end());
     248
     249        int64_t objectStoreId = metaDataKey.objectStoreId();
     250        String objectStoreName = decodeString(it->value().begin(), it->value().end());
    239251
    240252        it->next();
    241         if (!it->isValid()) {
     253        if (!checkObjectStoreAndMetaDataType(it.get(), stopKey, objectStoreId, 1)) {
    242254            LOG_ERROR("Internal Indexed DB error.");
    243255            return;
    244256        }
    245         bool autoIncrement = *it->value().begin();
    246 
    247         it->next(); // Is evicatble.
    248         if (!it->isValid()) {
     257        String keyPath = decodeString(it->value().begin(), it->value().end());
     258        bool hasKeyPath = true;
     259
     260        it->next();
     261        if (!checkObjectStoreAndMetaDataType(it.get(), stopKey, objectStoreId, 2)) {
    249262            LOG_ERROR("Internal Indexed DB error.");
    250263            return;
    251264        }
    252 
    253         it->next(); // Last version.
    254         if (!it->isValid()) {
     265        // FIXME: Add encode/decode functions for bools
     266        bool autoIncrement = *it->value().begin();
     267
     268        it->next(); // Is evicatble.
     269        if (!checkObjectStoreAndMetaDataType(it.get(), stopKey, objectStoreId, 3)) {
    255270            LOG_ERROR("Internal Indexed DB error.");
    256271            return;
    257272        }
    258273
    259         it->next(); // Maxium index id allocated.
    260         if (!it->isValid()) {
     274        it->next(); // Last version.
     275        if (!checkObjectStoreAndMetaDataType(it.get(), stopKey, objectStoreId, 4)) {
    261276            LOG_ERROR("Internal Indexed DB error.");
    262277            return;
    263278        }
    264279
     280        it->next(); // Maxium index id allocated.
     281        if (!checkObjectStoreAndMetaDataType(it.get(), stopKey, objectStoreId, 5)) {
     282            LOG_ERROR("Internal Indexed DB error.");
     283            return;
     284        }
     285
     286        it->next(); // [optional] has key path (is not null)
     287        if (checkObjectStoreAndMetaDataType(it.get(), stopKey, objectStoreId, 6)) {
     288            // FIXME: Add encode/decode functions for bools
     289            hasKeyPath = *it->value().begin();
     290            if (!hasKeyPath && !keyPath.isEmpty()) {
     291                LOG_ERROR("Internal Indexed DB error.");
     292                return;
     293            }
     294            it->next();
     295        }
     296
    265297        foundIds.append(objectStoreId);
    266298        foundNames.append(objectStoreName);
    267         foundKeyPaths.append(keyPath);
     299        foundKeyPaths.append(hasKeyPath ? keyPath : String());
    268300        foundAutoIncrementFlags.append(autoIncrement);
    269301    }
     
    299331    const Vector<char> lastVersionKey = ObjectStoreMetaDataKey::encode(databaseId, objectStoreId, 4);
    300332    const Vector<char> maxIndexIdKey = ObjectStoreMetaDataKey::encode(databaseId, objectStoreId, 5);
     333    const Vector<char> hasKeyPathKey  = ObjectStoreMetaDataKey::encode(databaseId, objectStoreId, 6);
    301334    const Vector<char> namesKey = ObjectStoreNamesKey::encode(databaseId, name);
    302335
     
    332365
    333366    ok = putInt(m_currentTransaction.get(), maxIndexIdKey, kMinimumIndexId);
     367    if (!ok) {
     368        LOG_ERROR("Internal Indexed DB error.");
     369        return false;
     370    }
     371
     372    ok = putInt(m_currentTransaction.get(), hasKeyPathKey, !keyPath.isNull());
    334373    if (!ok) {
    335374        LOG_ERROR("Internal Indexed DB error.");
     
    366405    getString(m_currentTransaction.get(), ObjectStoreMetaDataKey::encode(databaseId, objectStoreId, 0), objectStoreName);
    367406
    368     if (!deleteRange(m_currentTransaction.get(), ObjectStoreMetaDataKey::encode(databaseId, objectStoreId, 0), ObjectStoreMetaDataKey::encode(databaseId, objectStoreId, 6)))
     407    if (!deleteRange(m_currentTransaction.get(), ObjectStoreMetaDataKey::encode(databaseId, objectStoreId, 0), ObjectStoreMetaDataKey::encodeMaxKey(databaseId, objectStoreId)))
    369408        return; // FIXME: Report error.
    370409
  • trunk/Source/WebCore/storage/IDBLevelDBCoding.cpp

    r95901 r96007  
    7272//     <database id, 0, 0, 50, object store id, 4> => last "version" number [ObjectStoreMetaDataKey]
    7373//     <database id, 0, 0, 50, object store id, 5> => maximum index id ever allocated [ObjectStoreMetaDataKey]
     74//     <database id, 0, 0, 50, object store id, 6> => has key path (vs. null) [ObjectStoreMetaDataKey]
    7475//
    7576//
     
    878879}
    879880
     881Vector<char> ObjectStoreMetaDataKey::encodeMaxKey(int64_t databaseId, int64_t objectStoreId)
     882{
     883    return encode(databaseId, objectStoreId, INT64_MAX);
     884}
     885
    880886int64_t ObjectStoreMetaDataKey::objectStoreId() const
    881887{
  • trunk/Source/WebCore/storage/IDBLevelDBCoding.h

    r95901 r96007  
    145145    static Vector<char> encode(int64_t databaseId, int64_t objectStoreId, int64_t metaDataType);
    146146    static Vector<char> encodeMaxKey(int64_t databaseId);
     147    static Vector<char> encodeMaxKey(int64_t databaseId, int64_t objectStoreId);
    147148    int64_t objectStoreId() const;
    148149    int64_t metaDataType() const;
Note: See TracChangeset for help on using the changeset viewer.