Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Unified Diff: content/browser/indexed_db/indexed_db_database.cc

Issue 2735213002: Indexed DB: Ensure large explicit keys consistently max out generator (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/indexed_db/indexed_db_database.cc
diff --git a/content/browser/indexed_db/indexed_db_database.cc b/content/browser/indexed_db/indexed_db_database.cc
index ca13e95dbc151c70c4cee6a548773d9e4f02b851..896ebd9fb33a7b34bb1bf52aaf14dfd28cd27d9f 100644
--- a/content/browser/indexed_db/indexed_db_database.cc
+++ b/content/browser/indexed_db/indexed_db_database.cc
@@ -6,6 +6,7 @@
#include <math.h>
+#include <algorithm>
#include <limits>
#include <set>
@@ -1201,6 +1202,10 @@ static std::unique_ptr<IndexedDBKey> GenerateKey(
return base::MakeUnique<IndexedDBKey>(current_number, WebIDBKeyTypeNumber);
}
+// Called at the end of a "put" operation. The key is a number that was either
+// generated by the generator which now needs to be incremented (so
+// |check_current| is false) or was user-supplied so we only conditionally use
+// (and |check_current| is true).
static leveldb::Status UpdateKeyGenerator(IndexedDBBackingStore* backing_store,
IndexedDBTransaction* transaction,
int64_t database_id,
@@ -1208,9 +1213,13 @@ static leveldb::Status UpdateKeyGenerator(IndexedDBBackingStore* backing_store,
const IndexedDBKey& key,
bool check_current) {
DCHECK_EQ(WebIDBKeyTypeNumber, key.type());
+ // Maximum integer storable as ECMAScript number.
pwnall 2017/03/07 19:42:41 Technically not true, 9007199254740994 can also be
jsbell 2017/03/07 20:27:57 Yeah, bad comment (copied pasted from above). Need
+ const double max_generator_value = 9007199254740992.0;
+ int64_t value = base::saturated_cast<int64_t>(
+ floor(std::min(key.number(), max_generator_value)));
return backing_store->MaybeUpdateKeyGeneratorCurrentNumber(
transaction->BackingStoreTransaction(), database_id, object_store_id,
- static_cast<int64_t>(floor(key.number())) + 1, check_current);
+ value + 1, check_current);
}
struct IndexedDBDatabase::PutOperationParams {

Powered by Google App Engine
This is Rietveld 408576698