Changeset 128220 in webkit


Ignore:
Timestamp:
Sep 11, 2012 1:14:51 PM (12 years ago)
Author:
jamesr@google.com
Message:

Unreviewed, rolling out r128212.
http://trac.webkit.org/changeset/128212
https://bugs.webkit.org/show_bug.cgi?id=96037

Assertion fails on linux 64

  • Modules/indexeddb/IDBLevelDBCoding.cpp:

(WebCore::IDBLevelDBCoding::extractEncodedIDBKey):
(WebCore::IDBLevelDBCoding::compareEncodedIDBKeys):
(IDBLevelDBCoding):
(WebCore::IDBLevelDBCoding::compare):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r128217 r128220  
     12012-09-11  James Robinson  <jamesr@chromium.org>
     2
     3        Unreviewed, rolling out r128212.
     4        http://trac.webkit.org/changeset/128212
     5        https://bugs.webkit.org/show_bug.cgi?id=96037
     6
     7        Assertion fails on linux 64
     8
     9        * Modules/indexeddb/IDBLevelDBCoding.cpp:
     10        (WebCore::IDBLevelDBCoding::extractEncodedIDBKey):
     11        (WebCore::IDBLevelDBCoding::compareEncodedIDBKeys):
     12        (IDBLevelDBCoding):
     13        (WebCore::IDBLevelDBCoding::compare):
     14
    1152012-09-11  Joshua Bell  <jsbell@chromium.org>
    216
  • trunk/Source/WebCore/Modules/indexeddb/IDBLevelDBCoding.cpp

    r128212 r128220  
    506506}
    507507
    508 const char* extractEncodedIDBKey(const char* start, const char* limit, Vector<char>* result = 0)
    509 {
     508const char* extractEncodedIDBKey(const char* start, const char* limit, Vector<char>* result)
     509{
     510    ASSERT(result);
    510511    const char* p = start;
    511512    if (p >= limit)
     
    517518    case IDBKeyNullTypeByte:
    518519    case IDBKeyMinKeyTypeByte:
    519         break;
     520        *result = encodeByte(type);
     521        return p;
    520522    case IDBKeyArrayTypeByte: {
    521523        int64_t length;
     
    525527        if (length < 0)
    526528            return 0;
     529        result->clear();
     530        result->append(start, p - start);
    527531        while (length--) {
    528             p = extractEncodedIDBKey(p, limit);
     532            Vector<char> subkey;
     533            p = extractEncodedIDBKey(p, limit, &subkey);
    529534            if (!p)
    530535                return 0;
     536            result->append(subkey);
    531537        }
    532         break;
     538        return p;
    533539    }
    534540    case IDBKeyStringTypeByte: {
     
    539545        if (p + length * 2 > limit)
    540546            return 0;
    541         p += length * 2;
    542         break;
     547        result->clear();
     548        result->append(start, p - start + length * 2);
     549        return p + length * 2;
    543550    }
    544551    case IDBKeyDateTypeByte:
     
    546553        if (p + sizeof(double) > limit)
    547554            return 0;
    548         p += sizeof(double);
    549         break;
    550     }
    551 
    552     if (result) {
    553         ASSERT(p);
    554         ASSERT(p <= limit);
    555555        result->clear();
    556         result->append(start, p - start);
    557     }
    558 
    559     return p;
     556        result->append(start, 1 + sizeof(double));
     557        return p + sizeof(double);
     558    }
     559    ASSERT_NOT_REACHED();
     560    return 0;
    560561}
    561562
     
    581582}
    582583
    583 int compareEncodedIDBKeys(const char*& ptrA, const char* limitA, const char*& ptrB, const char* limitB)
    584 {
    585     ASSERT(&ptrA != &ptrB);
    586     ASSERT(ptrA < limitA);
    587     ASSERT(ptrB < limitB);
    588     unsigned char typeA = *ptrA++;
    589     unsigned char typeB = *ptrB++;
     584int compareEncodedIDBKeys(const char*& p, const char* limitA, const char*& q, const char* limitB)
     585{
     586    ASSERT(&p != &q);
     587    ASSERT(p < limitA);
     588    ASSERT(q < limitB);
     589    unsigned char typeA = *p++;
     590    unsigned char typeB = *q++;
    590591
    591592    if (int x = IDBKey::compareTypes(keyTypeByteToKeyType(typeA), keyTypeByteToKeyType(typeB)))
     
    599600    case IDBKeyArrayTypeByte: {
    600601        int64_t lengthA, lengthB;
    601         ptrA = decodeVarInt(ptrA, limitA, lengthA);
    602         if (!ptrA)
    603             return 0;
    604         ptrB = decodeVarInt(ptrB, limitB, lengthB);
    605         if (!ptrB)
     602        p = decodeVarInt(p, limitA, lengthA);
     603        if (!p)
     604            return 0;
     605        q = decodeVarInt(q, limitB, lengthB);
     606        if (!q)
    606607            return 0;
    607608        if (lengthA < 0 || lengthB < 0)
    608609            return 0;
    609610        for (int64_t i = 0; i < lengthA && i < lengthB; ++i) {
    610             if (int cmp = compareEncodedIDBKeys(ptrA, limitA, ptrB, limitB))
     611            if (int cmp = compareEncodedIDBKeys(p, limitA, q, limitB))
    611612                return cmp;
    612613        }
     
    618619    }
    619620    case IDBKeyStringTypeByte:
    620         return compareEncodedStringsWithLength(ptrA, limitA, ptrB, limitB);
     621        return compareEncodedStringsWithLength(p, limitA, q, limitB);
    621622    case IDBKeyDateTypeByte:
    622623    case IDBKeyNumberTypeByte: {
    623624        double d, e;
    624         ptrA = decodeDouble(ptrA, limitA, &d);
    625         ASSERT(ptrA);
    626         ptrB = decodeDouble(ptrB, limitB, &e);
    627         ASSERT(ptrB);
     625        p = decodeDouble(p, limitA, &d);
     626        ASSERT(p);
     627        q = decodeDouble(q, limitB, &e);
     628        ASSERT(q);
    628629        if (d < e)
    629630            return -1;
     
    643644    ASSERT(keyB.size() >= 1);
    644645
    645     const char* ptrA = keyA.data();
    646     const char* limitA = ptrA + keyA.size();
    647     const char* ptrB = keyB.data();
    648     const char* limitB = ptrB + keyB.size();
    649 
    650     return compareEncodedIDBKeys(ptrA, limitA, ptrB, limitB);
     646    const char* p = keyA.data();
     647    const char* limitA = p + keyA.size();
     648    const char* q = keyB.data();
     649    const char* limitB = q + keyB.size();
     650
     651    return compareEncodedIDBKeys(p, limitA, q, limitB);
    651652}
    652653
     
    720721
    721722namespace {
    722 
    723723template<typename KeyType>
    724 int compare(const LevelDBSlice& a, const LevelDBSlice& b, bool ignoreDuplicates = false)
     724int decodeAndCompare(const LevelDBSlice& a, const LevelDBSlice& b)
    725725{
    726726    KeyType keyA;
     
    734734    return keyA.compare(keyB);
    735735}
    736 
    737 template<>
    738 int compare<ExistsEntryKey>(const LevelDBSlice& a, const LevelDBSlice& b, bool ignoreDuplicates)
    739 {
    740     KeyPrefix prefixA;
    741     KeyPrefix prefixB;
    742     const char* ptrA = KeyPrefix::decode(a.begin(), a.end(), &prefixA);
    743     const char* ptrB = KeyPrefix::decode(b.begin(), b.end(), &prefixB);
    744     ASSERT(ptrA);
    745     ASSERT(ptrB);
    746     ASSERT(prefixA.m_databaseId);
    747     ASSERT(prefixA.m_objectStoreId);
    748     ASSERT(prefixA.m_indexId == ExistsEntryKey::SpecialIndexNumber);
    749     ASSERT(prefixB.m_databaseId);
    750     ASSERT(prefixB.m_objectStoreId);
    751     ASSERT(prefixB.m_indexId == ExistsEntryKey::SpecialIndexNumber);
    752     ASSERT(ptrA != a.end());
    753     ASSERT(ptrB != b.end());
    754     // Prefixes are not compared - it is assumed this was already done.
    755     ASSERT(!prefixA.compare(prefixB));
    756 
    757     return compareEncodedIDBKeys(ptrA, a.end(), ptrB, b.end());
    758 }
    759 
    760 template<>
    761 int compare<ObjectStoreDataKey>(const LevelDBSlice& a, const LevelDBSlice& b, bool ignoreDuplicates)
    762 {
    763     KeyPrefix prefixA;
    764     KeyPrefix prefixB;
    765     const char* ptrA = KeyPrefix::decode(a.begin(), a.end(), &prefixA);
    766     const char* ptrB = KeyPrefix::decode(b.begin(), b.end(), &prefixB);
    767     ASSERT(ptrA);
    768     ASSERT(ptrB);
    769     ASSERT(prefixA.m_databaseId);
    770     ASSERT(prefixA.m_objectStoreId);
    771     ASSERT(prefixA.m_indexId == ObjectStoreDataKey::SpecialIndexNumber);
    772     ASSERT(prefixB.m_databaseId);
    773     ASSERT(prefixB.m_objectStoreId);
    774     ASSERT(prefixB.m_indexId == ObjectStoreDataKey::SpecialIndexNumber);
    775     ASSERT(ptrA != a.end());
    776     ASSERT(ptrB != b.end());
    777     // Prefixes are not compared - it is assumed this was already done.
    778     ASSERT(!prefixA.compare(prefixB));
    779 
    780     return compareEncodedIDBKeys(ptrA, a.end(), ptrB, b.end());
    781 }
    782 
    783 template<>
    784 int compare<IndexDataKey>(const LevelDBSlice& a, const LevelDBSlice& b, bool ignoreDuplicates)
    785 {
    786     KeyPrefix prefixA;
    787     KeyPrefix prefixB;
    788     const char* ptrA = KeyPrefix::decode(a.begin(), a.end(), &prefixA);
    789     const char* ptrB = KeyPrefix::decode(b.begin(), b.end(), &prefixB);
    790     ASSERT(ptrA);
    791     ASSERT(ptrB);
    792     ASSERT(prefixA.m_databaseId);
    793     ASSERT(prefixA.m_objectStoreId);
    794     ASSERT(prefixA.m_indexId >= MinimumIndexId);
    795     ASSERT(prefixB.m_databaseId);
    796     ASSERT(prefixB.m_objectStoreId);
    797     ASSERT(prefixB.m_indexId >= MinimumIndexId);
    798     ASSERT(ptrA != a.end());
    799     ASSERT(ptrB != b.end());
    800     // Prefixes are not compared - it is assumed this was already done.
    801     ASSERT(!prefixA.compare(prefixB));
    802 
    803     // index key
    804     if (int x = compareEncodedIDBKeys(ptrA, a.end(), ptrB, b.end()))
    805         return x;
    806     if (ignoreDuplicates)
    807         return 0;
    808 
    809     // sequence number [optional]
    810     int64_t sequenceNumberA = -1;
    811     int64_t sequenceNumberB = -1;
    812     if (ptrA != a.end())
    813         ptrA = decodeVarInt(ptrA, a.end(), sequenceNumberA);
    814     if (ptrB != b.end())
    815         ptrB = decodeVarInt(ptrB, b.end(), sequenceNumberB);
    816 
    817     // primar key [optional]
    818     if (!ptrA || !ptrB)
    819         return 0;
    820     if (ptrA == a.end() && ptrB == b.end())
    821         return 0;
    822     if (ptrA == a.end())
    823         return -1;
    824     if (ptrB == b.end())
    825         return 1;
    826 
    827     if (int x = compareEncodedIDBKeys(ptrA, a.end(), ptrB, b.end()))
    828         return x;
    829 
    830     return compareInts(sequenceNumberA, sequenceNumberB);
    831 }
    832 
    833736}
    834737
     
    864767            return 0;
    865768        if (typeByteA == DatabaseFreeListTypeByte)
    866             return compare<DatabaseFreeListKey>(a, b);
     769            return decodeAndCompare<DatabaseFreeListKey>(a, b);
    867770        if (typeByteA == DatabaseNameTypeByte)
    868             return compare<DatabaseNameKey>(a, b);
     771            return decodeAndCompare<DatabaseNameKey>(a, b);
    869772    }
    870773
     
    883786
    884787        if (typeByteA == ObjectStoreMetaDataTypeByte)
    885             return compare<ObjectStoreMetaDataKey>(a, b);
     788            return decodeAndCompare<ObjectStoreMetaDataKey>(a, b);
    886789        if (typeByteA == IndexMetaDataTypeByte)
    887             return compare<IndexMetaDataKey>(a, b);
     790            return decodeAndCompare<IndexMetaDataKey>(a, b);
    888791        if (typeByteA == ObjectStoreFreeListTypeByte)
    889             return compare<ObjectStoreFreeListKey>(a, b);
     792            return decodeAndCompare<ObjectStoreFreeListKey>(a, b);
    890793        if (typeByteA == IndexFreeListTypeByte)
    891             return compare<IndexFreeListKey>(a, b);
     794            return decodeAndCompare<IndexFreeListKey>(a, b);
    892795        if (typeByteA == ObjectStoreNamesTypeByte)
    893             return compare<ObjectStoreNamesKey>(a, b);
     796            return decodeAndCompare<ObjectStoreNamesKey>(a, b);
    894797        if (typeByteA == IndexNamesKeyTypeByte)
    895             return compare<IndexNamesKey>(a, b);
    896 
     798            return decodeAndCompare<IndexNamesKey>(a, b);
     799
     800        return 0;
    897801        ASSERT_NOT_REACHED();
    898         return 0;
    899802    }
    900803
     
    907810            return 1; // FIXME: This case of non-existing user keys should not have to be handled this way.
    908811
    909         return compare<ObjectStoreDataKey>(a, b);
     812        return decodeAndCompare<ObjectStoreDataKey>(a, b);
    910813    }
    911814    if (prefixA.type() == KeyPrefix::ExistsEntry) {
     
    917820            return 1; // FIXME: This case of non-existing user keys should not have to be handled this way.
    918821
    919         return compare<ExistsEntryKey>(a, b);
     822        return decodeAndCompare<ExistsEntryKey>(a, b);
    920823    }
    921824    if (prefixA.type() == KeyPrefix::IndexData) {
     
    927830            return 1; // FIXME: This case of non-existing user keys should not have to be handled this way.
    928831
     832        IndexDataKey indexDataKeyA;
     833        IndexDataKey indexDataKeyB;
     834
     835        ptrA = IndexDataKey::decode(a.begin(), endA, &indexDataKeyA);
     836        ptrB = IndexDataKey::decode(b.begin(), endB, &indexDataKeyB);
     837        ASSERT(ptrA);
     838        ASSERT(ptrB);
     839
    929840        bool ignoreDuplicates = indexKeys;
    930         return compare<IndexDataKey>(a, b, ignoreDuplicates);
     841        return indexDataKeyA.compare(indexDataKeyB, ignoreDuplicates);
    931842    }
    932843
Note: See TracChangeset for help on using the changeset viewer.