Skip to content

Commit

Permalink
fix: update dom_storage_limits.patch (fixes electron#13465)
Browse files Browse the repository at this point in the history
The previous version of this patch did not include
changes required to circumvent the quota enforcement
performed by StorageAreaImpl. Consequently when
the quota was exceeded, things still "appeared to
work" at first but then would later fail silently.
That is, the cache would be updated but the backing
store would not.

Refer to the discussion linked below for more information:
electron#13465 (comment)
  • Loading branch information
jacobq committed Oct 31, 2019
1 parent 23ca7e3 commit 9d90659
Showing 1 changed file with 39 additions and 16 deletions.
55 changes: 39 additions & 16 deletions patches/chromium/dom_storage_limits.patch
Expand Up @@ -32,49 +32,72 @@ for a given `BrowserWindow` via a `webPreferences` option,
similar to [`nodeIntegration`](https://electronjs.org/docs/tutorial/security#2-disable-nodejs-integration-for-remote-content).

diff --git a/content/browser/dom_storage/dom_storage_types.h b/content/browser/dom_storage/dom_storage_types.h
index 6c0b831ebaaa2c1749bbc7436ce1025656588310..b67767751cadc6072c133297c7a6cdcc6bfd0c98 100644
index 6c0b831ebaaa..fcf2456debab 100644
--- a/content/browser/dom_storage/dom_storage_types.h
+++ b/content/browser/dom_storage/dom_storage_types.h
@@ -21,6 +21,7 @@ typedef std::map<base::string16, base::NullableString16> DOMStorageValuesMap;

// The quota for each storage area.
// This value is enforced in renderer processes and the browser process.
+// However, Electron's dom_storage_limits.patch removes the code that checks this limit.
+// (Electron's dom_storage_limits.patch disables quota enforcement.)
const size_t kPerStorageAreaQuota = 10 * 1024 * 1024;

// In the browser process we allow some overage to
diff --git a/content/browser/dom_storage/storage_area_impl.cc b/content/browser/dom_storage/storage_area_impl.cc
index 4b48b5f16a3e..b9e83279d1fc 100644
--- a/content/browser/dom_storage/storage_area_impl.cc
+++ b/content/browser/dom_storage/storage_area_impl.cc
@@ -303,6 +303,8 @@ void StorageAreaImpl::Put(

// Only check quota if the size is increasing, this allows
// shrinking changes to pre-existing maps that are over budget.
+ // (Electron's dom_storage_limits.patch has disabled this.)
+ #if 0
if (new_item_size > old_item_size && new_storage_used > max_size_) {
if (map_state_ == MapState::LOADED_KEYS_ONLY) {
receivers_.ReportBadMessage(
@@ -313,6 +315,7 @@ void StorageAreaImpl::Put(
}
return;
}
+ #endif

if (database_) {
CreateCommitBatchIfNeeded();
diff --git a/third_party/blink/renderer/modules/storage/cached_storage_area.cc b/third_party/blink/renderer/modules/storage/cached_storage_area.cc
index d91fdc2a7d52307126bc04d44167edadb8c743a8..630acfca527aaec44742d45e47ce29d7754e3385 100644
index d91fdc2a7d52..7cb3cbf34d3a 100644
--- a/third_party/blink/renderer/modules/storage/cached_storage_area.cc
+++ b/third_party/blink/renderer/modules/storage/cached_storage_area.cc
@@ -107,11 +107,13 @@ bool CachedStorageArea::SetItem(const String& key,
@@ -107,11 +107,14 @@ bool CachedStorageArea::SetItem(const String& key,
Source* source) {
DCHECK(areas_->Contains(source));

+#if 0

+ // (Electron's dom_storage_limits.patch has disabled this.)
+ #if 0
// A quick check to reject obviously overbudget items to avoid priming the
// cache.
if ((key.length() + value.length()) * 2 >
mojom::blink::StorageArea::kPerStorageAreaQuota)
return false;
+#endif
+ #endif

EnsureLoaded();
String old_value;
diff --git a/third_party/blink/renderer/modules/storage/storage_area_map.cc b/third_party/blink/renderer/modules/storage/storage_area_map.cc
index 0da8a1e891edad60355792c40b7d15e90c1086e8..df71418d598d5bdf41e9a8a4340999d9d277aeef 100644
index 0da8a1e891ed..5a1811419030 100644
--- a/third_party/blink/renderer/modules/storage/storage_area_map.cc
+++ b/third_party/blink/renderer/modules/storage/storage_area_map.cc
@@ -113,10 +113,12 @@ bool StorageAreaMap::SetItemInternal(const String& key,
@@ -113,10 +113,13 @@ bool StorageAreaMap::SetItemInternal(const String& key,
size_t new_quota_used = quota_used_ - old_item_size + new_item_size;
size_t new_memory_used = memory_used_ - old_item_memory + new_item_memory;

+#if 0

+ // (Electron's dom_storage_limits.patch has disabled this.)
+ #if 0
// Only check quota if the size is increasing, this allows
// shrinking changes to pre-existing files that are over budget.
if (check_quota && new_item_size > old_item_size && new_quota_used > quota_)
return false;
+#endif
+ #endif

keys_values_.Set(key, value);
ResetKeyIterator();

0 comments on commit 9d90659

Please sign in to comment.