Title: [276773] trunk
Revision
276773
Author
[email protected]
Date
2021-04-29 07:27:23 -0700 (Thu, 29 Apr 2021)

Log Message

Unreviewed, reverting r276689, r276736, and r276737.
https://bugs.webkit.org/show_bug.cgi?id=225188

Broke platform/ios/ios/storage/domstorage/5mb-quota.html

Reverted changesets:

"Improve local storage size estimation for quota limitation"
https://bugs.webkit.org/show_bug.cgi?id=225123
https://trac.webkit.org/changeset/276689

"REGRESSION(r276689): [ iOS wk2 ]
platform/ios/ios/storage/domstorage/5mb-quota.html is a
constant text failure"
https://bugs.webkit.org/show_bug.cgi?id=225160
https://trac.webkit.org/changeset/276736

"Make sure we invalidate the iterator in StorageMap::clear()"
https://bugs.webkit.org/show_bug.cgi?id=225164
https://trac.webkit.org/changeset/276737

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (276772 => 276773)


--- trunk/LayoutTests/ChangeLog	2021-04-29 14:15:53 UTC (rev 276772)
+++ trunk/LayoutTests/ChangeLog	2021-04-29 14:27:23 UTC (rev 276773)
@@ -1,3 +1,26 @@
+2021-04-29  Commit Queue  <[email protected]>
+
+        Unreviewed, reverting r276689, r276736, and r276737.
+        https://bugs.webkit.org/show_bug.cgi?id=225188
+
+        Broke platform/ios/ios/storage/domstorage/5mb-quota.html
+
+        Reverted changesets:
+
+        "Improve local storage size estimation for quota limitation"
+        https://bugs.webkit.org/show_bug.cgi?id=225123
+        https://trac.webkit.org/changeset/276689
+
+        "REGRESSION(r276689): [ iOS wk2 ]
+        platform/ios/ios/storage/domstorage/5mb-quota.html is a
+        constant text failure"
+        https://bugs.webkit.org/show_bug.cgi?id=225160
+        https://trac.webkit.org/changeset/276736
+
+        "Make sure we invalidate the iterator in StorageMap::clear()"
+        https://bugs.webkit.org/show_bug.cgi?id=225164
+        https://trac.webkit.org/changeset/276737
+
 2021-04-29  Zalan Bujtas  <[email protected]>
 
         [LFC][IFC] Incorrect middle alignment for inline boxes when line-height is present

Modified: trunk/LayoutTests/platform/ios/ios/storage/domstorage/5mb-quota.html (276772 => 276773)


--- trunk/LayoutTests/platform/ios/ios/storage/domstorage/5mb-quota.html	2021-04-29 14:15:53 UTC (rev 276772)
+++ trunk/LayoutTests/platform/ios/ios/storage/domstorage/5mb-quota.html	2021-04-29 14:27:23 UTC (rev 276773)
@@ -22,7 +22,7 @@
     shouldBe("storage.length", "0");
 
     debug("Creating 'data' which contains 64K of data");
-    data = ""
+    data = ""
     for (var i=0; i<16; i++)
         data += data;
     shouldBe("data.length", "65536");

Modified: trunk/LayoutTests/storage/domstorage/quota.html (276772 => 276773)


--- trunk/LayoutTests/storage/domstorage/quota.html	2021-04-29 14:15:53 UTC (rev 276772)
+++ trunk/LayoutTests/storage/domstorage/quota.html	2021-04-29 14:27:23 UTC (rev 276773)
@@ -22,7 +22,7 @@
     shouldBe("storage.length", "0");
 
     debug("Creating 'data' which contains 64K of data");
-    data = ""
+    data = ""
     for (var i=0; i<16; i++)
         data += data;
     shouldBe("data.length", "65536");

Modified: trunk/Source/WebCore/ChangeLog (276772 => 276773)


--- trunk/Source/WebCore/ChangeLog	2021-04-29 14:15:53 UTC (rev 276772)
+++ trunk/Source/WebCore/ChangeLog	2021-04-29 14:27:23 UTC (rev 276773)
@@ -1,3 +1,26 @@
+2021-04-29  Commit Queue  <[email protected]>
+
+        Unreviewed, reverting r276689, r276736, and r276737.
+        https://bugs.webkit.org/show_bug.cgi?id=225188
+
+        Broke platform/ios/ios/storage/domstorage/5mb-quota.html
+
+        Reverted changesets:
+
+        "Improve local storage size estimation for quota limitation"
+        https://bugs.webkit.org/show_bug.cgi?id=225123
+        https://trac.webkit.org/changeset/276689
+
+        "REGRESSION(r276689): [ iOS wk2 ]
+        platform/ios/ios/storage/domstorage/5mb-quota.html is a
+        constant text failure"
+        https://bugs.webkit.org/show_bug.cgi?id=225160
+        https://trac.webkit.org/changeset/276736
+
+        "Make sure we invalidate the iterator in StorageMap::clear()"
+        https://bugs.webkit.org/show_bug.cgi?id=225164
+        https://trac.webkit.org/changeset/276737
+
 2021-04-29  Antoine Quint  <[email protected]>
 
         Rotation axis parallel to the z axis should not serialize using the "z" keyword for the rotate property

Modified: trunk/Source/WebCore/storage/StorageMap.cpp (276772 => 276773)


--- trunk/Source/WebCore/storage/StorageMap.cpp	2021-04-29 14:15:53 UTC (rev 276772)
+++ trunk/Source/WebCore/storage/StorageMap.cpp	2021-04-29 14:27:23 UTC (rev 276773)
@@ -26,7 +26,6 @@
 #include "config.h"
 #include "StorageMap.h"
 
-#include <wtf/CheckedArithmetic.h>
 #include <wtf/SetForScope.h>
 
 namespace WebCore {
@@ -94,19 +93,26 @@
     if (m_impl->refCount() > 1)
         m_impl = m_impl->copy();
 
+    // Quota tracking.  This is done in a couple of steps to keep the overflow tracking simple.
+    unsigned newLength = m_impl->currentLength;
+    bool overflow = newLength + value.length() < newLength;
+    newLength += value.length();
+
     oldValue = m_impl->map.get(key);
+    overflow |= newLength - oldValue.length() > newLength;
+    newLength -= oldValue.length();
 
-    // Quota tracking. This is done in a couple of steps to keep the overflow tracking simple.
-    CheckedUint32 newSize = m_impl->currentSize;
-    newSize -= oldValue.sizeInBytes();
-    newSize += value.sizeInBytes();
-    if (oldValue.isNull())
-        newSize += key.sizeInBytes();
-    if (m_quotaSize != noQuota && (newSize.hasOverflowed() || newSize.unsafeGet() > m_quotaSize)) {
+    unsigned adjustedKeyLength = oldValue.isNull() ? key.length() : 0;
+    overflow |= newLength + adjustedKeyLength < newLength;
+    newLength += adjustedKeyLength;
+
+    ASSERT(!overflow);  // Overflow is bad...even if quotas are off.
+    bool overQuota = newLength > m_quotaSize / sizeof(UChar);
+    if (m_quotaSize != noQuota && (overflow || overQuota)) {
         quotaException = true;
         return;
     }
-    m_impl->currentSize = newSize.unsafeGet();
+    m_impl->currentLength = newLength;
 
     HashMap<String, String>::AddResult addResult = m_impl->map.add(key, value);
     if (!addResult.isNewEntry)
@@ -117,7 +123,7 @@
 
 void StorageMap::setItemIgnoringQuota(const String& key, const String& value)
 {
-    SetForScope<unsigned> quotaSizeChange(m_quotaSize, noQuota);
+    SetForScope<unsigned> quotaSizeChange(m_quotaSize, static_cast<unsigned>(noQuota));
 
     String oldValue;
     bool quotaException;
@@ -132,14 +138,13 @@
         m_impl = m_impl->copy();
 
     oldValue = m_impl->map.take(key);
-    if (oldValue.isNull())
-        return;
-
-    invalidateIterator();
-    ASSERT(m_impl->currentSize - key.sizeInBytes() <= m_impl->currentSize);
-    m_impl->currentSize -= key.sizeInBytes();
-    ASSERT(m_impl->currentSize - oldValue.sizeInBytes() <= m_impl->currentSize);
-    m_impl->currentSize -= oldValue.sizeInBytes();
+    if (!oldValue.isNull()) {
+        invalidateIterator();
+        ASSERT(m_impl->currentLength - key.length() <= m_impl->currentLength);
+        m_impl->currentLength -= key.length();
+    }
+    ASSERT(m_impl->currentLength - oldValue.length() <= m_impl->currentLength);
+    m_impl->currentLength -= oldValue.length();
 }
 
 void StorageMap::clear()
@@ -149,8 +154,7 @@
         return;
     }
     m_impl->map.clear();
-    m_impl->currentSize = 0;
-    invalidateIterator();
+    m_impl->currentLength = 0;
 }
 
 bool StorageMap::contains(const String& key) const
@@ -164,8 +168,8 @@
         // Fast path.
         m_impl->map = WTFMove(items);
         for (auto& pair : m_impl->map) {
-            ASSERT(m_impl->currentSize + pair.key.sizeInBytes() + pair.value.sizeInBytes() >= m_impl->currentSize);
-            m_impl->currentSize += (pair.key.sizeInBytes() + pair.value.sizeInBytes());
+            ASSERT(m_impl->currentLength + pair.key.length() + pair.value.length() >= m_impl->currentLength);
+            m_impl->currentLength += (pair.key.length() + pair.value.length());
         }
         return;
     }
@@ -174,9 +178,9 @@
         auto& key = item.key;
         auto& value = item.value;
 
-        ASSERT(m_impl->currentSize + key.sizeInBytes() + value.sizeInBytes() >= m_impl->currentSize);
-        m_impl->currentSize += (key.sizeInBytes() + value.sizeInBytes());
-
+        ASSERT(m_impl->currentLength + key.length() + value.length() >= m_impl->currentLength);
+        m_impl->currentLength += (key.length() + value.length());
+        
         auto result = m_impl->map.add(WTFMove(key), WTFMove(value));
         ASSERT_UNUSED(result, result.isNewEntry); // True if the key didn't exist previously.
     }
@@ -186,7 +190,7 @@
 {
     auto copy = Impl::create();
     copy->map = map;
-    copy->currentSize = currentSize;
+    copy->currentLength = currentLength;
     return copy;
 }
 

Modified: trunk/Source/WebCore/storage/StorageMap.h (276772 => 276773)


--- trunk/Source/WebCore/storage/StorageMap.h	2021-04-29 14:15:53 UTC (rev 276772)
+++ trunk/Source/WebCore/storage/StorageMap.h	2021-04-29 14:27:23 UTC (rev 276773)
@@ -56,7 +56,7 @@
 
     bool isShared() const { return !m_impl->hasOneRef(); }
 
-    static constexpr unsigned noQuota = std::numeric_limits<unsigned>::max();
+    static constexpr unsigned noQuota = UINT_MAX;
 
 private:
     void invalidateIterator();
@@ -73,7 +73,7 @@
         HashMap<String, String> map;
         HashMap<String, String>::iterator iterator { map.end() };
         unsigned iteratorIndex { std::numeric_limits<unsigned>::max() };
-        unsigned currentSize { 0 };
+        unsigned currentLength { 0 }; // Measured in UChars.
     };
 
     Ref<Impl> m_impl;

Modified: trunk/Source/WebKit/ChangeLog (276772 => 276773)


--- trunk/Source/WebKit/ChangeLog	2021-04-29 14:15:53 UTC (rev 276772)
+++ trunk/Source/WebKit/ChangeLog	2021-04-29 14:27:23 UTC (rev 276773)
@@ -1,3 +1,26 @@
+2021-04-29  Commit Queue  <[email protected]>
+
+        Unreviewed, reverting r276689, r276736, and r276737.
+        https://bugs.webkit.org/show_bug.cgi?id=225188
+
+        Broke platform/ios/ios/storage/domstorage/5mb-quota.html
+
+        Reverted changesets:
+
+        "Improve local storage size estimation for quota limitation"
+        https://bugs.webkit.org/show_bug.cgi?id=225123
+        https://trac.webkit.org/changeset/276689
+
+        "REGRESSION(r276689): [ iOS wk2 ]
+        platform/ios/ios/storage/domstorage/5mb-quota.html is a
+        constant text failure"
+        https://bugs.webkit.org/show_bug.cgi?id=225160
+        https://trac.webkit.org/changeset/276736
+
+        "Make sure we invalidate the iterator in StorageMap::clear()"
+        https://bugs.webkit.org/show_bug.cgi?id=225164
+        https://trac.webkit.org/changeset/276737
+
 2021-04-29  Said Abou-Hallawa  <[email protected]>
 
         Fix build break after r276753

Modified: trunk/Source/WebKit/NetworkProcess/WebStorage/LocalStorageDatabase.cpp (276772 => 276773)


--- trunk/Source/WebKit/NetworkProcess/WebStorage/LocalStorageDatabase.cpp	2021-04-29 14:15:53 UTC (rev 276772)
+++ trunk/Source/WebKit/NetworkProcess/WebStorage/LocalStorageDatabase.cpp	2021-04-29 14:27:23 UTC (rev 276773)
@@ -47,6 +47,14 @@
 
 static const char getItemsQueryString[] = "SELECT key, value FROM ItemTable";
 
+static CheckedUint64 estimateEntrySize(const String& key, const String& value)
+{
+    CheckedUint64 entrySize;
+    entrySize += key.length() * sizeof(UChar);
+    entrySize += value.length() * sizeof(UChar);
+    return entrySize;
+}
+
 Ref<LocalStorageDatabase> LocalStorageDatabase::create(Ref<WorkQueue>&& queue, Ref<LocalStorageDatabaseTracker>&& tracker, const SecurityOriginData& securityOrigin, unsigned quotaInBytes)
 {
     return adoptRef(*new LocalStorageDatabase(WTFMove(queue), WTFMove(tracker), securityOrigin, quotaInBytes));
@@ -209,11 +217,11 @@
     }
 
     if (m_databaseSize) {
-        auto sizeDecrease = key.sizeInBytes() + oldValue.sizeInBytes();
-        if (sizeDecrease >= *m_databaseSize)
+        CheckedUint64 entrySize = estimateEntrySize(key, oldValue);
+        if (entrySize.hasOverflowed() || entrySize.unsafeGet() >= *m_databaseSize)
             *m_databaseSize = 0;
         else
-            *m_databaseSize -= sizeDecrease;
+            *m_databaseSize -= entrySize.unsafeGet();
     }
 }
 
@@ -246,16 +254,15 @@
     if (!m_database.isOpen())
         return;
 
-    oldValue = item(key);
-
     if (m_quotaInBytes != WebCore::StorageMap::noQuota) {
         if (!m_databaseSize)
             m_databaseSize = SQLiteFileSystem::getDatabaseFileSize(m_databasePath);
-        CheckedUint32 newDatabaseSize = *m_databaseSize;
-        newDatabaseSize -= oldValue.sizeInBytes();
-        newDatabaseSize += value.sizeInBytes();
-        if (oldValue.isNull())
-            newDatabaseSize += key.sizeInBytes();
+        if (*m_databaseSize >= m_quotaInBytes) {
+            quotaException = true;
+            return;
+        }
+        CheckedUint64 newDatabaseSize = *m_databaseSize;
+        newDatabaseSize += estimateEntrySize(key, value);
         if (newDatabaseSize.hasOverflowed() || newDatabaseSize.unsafeGet() > m_quotaInBytes) {
             quotaException = true;
             return;
@@ -263,6 +270,8 @@
         m_databaseSize = newDatabaseSize.unsafeGet();
     }
 
+    oldValue = item(key);
+
     auto insertStatement = scopedStatement(m_insertStatement, "INSERT INTO ItemTable VALUES (?, ?)"_s);
     if (!insertStatement) {
         LOG_ERROR("Failed to prepare insert statement - cannot write to local storage database");

Modified: trunk/Source/WebKit/NetworkProcess/WebStorage/LocalStorageDatabase.h (276772 => 276773)


--- trunk/Source/WebKit/NetworkProcess/WebStorage/LocalStorageDatabase.h	2021-04-29 14:15:53 UTC (rev 276772)
+++ trunk/Source/WebKit/NetworkProcess/WebStorage/LocalStorageDatabase.h	2021-04-29 14:27:23 UTC (rev 276773)
@@ -75,10 +75,10 @@
 
     String m_databasePath;
     mutable WebCore::SQLiteDatabase m_database;
-    const unsigned m_quotaInBytes { 0 };
+    unsigned m_quotaInBytes { 0 };
     bool m_failedToOpenDatabase { false };
     bool m_isClosed { false };
-    Optional<unsigned> m_databaseSize;
+    Optional<uint64_t> m_databaseSize;
 
     std::unique_ptr<WebCore::SuddenTerminationDisabler> m_disableSuddenTerminationWhileWritingToLocalStorage;
     mutable std::unique_ptr<WebCore::SQLiteStatement> m_clearStatement;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to