Changeset 96007 in webkit
- Timestamp:
- Sep 26, 2011 3:22:23 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r96000 r96007 1 2011-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 1 18 2011-09-26 John Bauman <jbauman@chromium.org> 2 19 -
trunk/Source/WebCore/storage/IDBLevelDBBackingStore.cpp
r95901 r96007 213 213 } 214 214 215 static 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 215 230 void IDBLevelDBBackingStore::getObjectStores(int64_t databaseId, Vector<int64_t>& foundIds, Vector<String>& foundNames, Vector<String>& foundKeyPaths, Vector<bool>& foundAutoIncrementFlags) 216 231 { … … 219 234 220 235 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) { 222 238 const char *p = it->key().begin(); 223 239 const char *limit = it->key().end(); … … 226 242 p = ObjectStoreMetaDataKey::decode(p, limit, &metaDataKey); 227 243 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()) { 235 245 LOG_ERROR("Internal Indexed DB error."); 236 246 return; 237 247 } 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()); 239 251 240 252 it->next(); 241 if (! it->isValid()) {253 if (!checkObjectStoreAndMetaDataType(it.get(), stopKey, objectStoreId, 1)) { 242 254 LOG_ERROR("Internal Indexed DB error."); 243 255 return; 244 256 } 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)) { 249 262 LOG_ERROR("Internal Indexed DB error."); 250 263 return; 251 264 } 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)) { 255 270 LOG_ERROR("Internal Indexed DB error."); 256 271 return; 257 272 } 258 273 259 it->next(); // Maxium index id allocated.260 if (! it->isValid()) {274 it->next(); // Last version. 275 if (!checkObjectStoreAndMetaDataType(it.get(), stopKey, objectStoreId, 4)) { 261 276 LOG_ERROR("Internal Indexed DB error."); 262 277 return; 263 278 } 264 279 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 265 297 foundIds.append(objectStoreId); 266 298 foundNames.append(objectStoreName); 267 foundKeyPaths.append( keyPath);299 foundKeyPaths.append(hasKeyPath ? keyPath : String()); 268 300 foundAutoIncrementFlags.append(autoIncrement); 269 301 } … … 299 331 const Vector<char> lastVersionKey = ObjectStoreMetaDataKey::encode(databaseId, objectStoreId, 4); 300 332 const Vector<char> maxIndexIdKey = ObjectStoreMetaDataKey::encode(databaseId, objectStoreId, 5); 333 const Vector<char> hasKeyPathKey = ObjectStoreMetaDataKey::encode(databaseId, objectStoreId, 6); 301 334 const Vector<char> namesKey = ObjectStoreNamesKey::encode(databaseId, name); 302 335 … … 332 365 333 366 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()); 334 373 if (!ok) { 335 374 LOG_ERROR("Internal Indexed DB error."); … … 366 405 getString(m_currentTransaction.get(), ObjectStoreMetaDataKey::encode(databaseId, objectStoreId, 0), objectStoreName); 367 406 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))) 369 408 return; // FIXME: Report error. 370 409 -
trunk/Source/WebCore/storage/IDBLevelDBCoding.cpp
r95901 r96007 72 72 // <database id, 0, 0, 50, object store id, 4> => last "version" number [ObjectStoreMetaDataKey] 73 73 // <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] 74 75 // 75 76 // … … 878 879 } 879 880 881 Vector<char> ObjectStoreMetaDataKey::encodeMaxKey(int64_t databaseId, int64_t objectStoreId) 882 { 883 return encode(databaseId, objectStoreId, INT64_MAX); 884 } 885 880 886 int64_t ObjectStoreMetaDataKey::objectStoreId() const 881 887 { -
trunk/Source/WebCore/storage/IDBLevelDBCoding.h
r95901 r96007 145 145 static Vector<char> encode(int64_t databaseId, int64_t objectStoreId, int64_t metaDataType); 146 146 static Vector<char> encodeMaxKey(int64_t databaseId); 147 static Vector<char> encodeMaxKey(int64_t databaseId, int64_t objectStoreId); 147 148 int64_t objectStoreId() const; 148 149 int64_t metaDataType() const;
Note: See TracChangeset
for help on using the changeset viewer.