Title: [248366] trunk/Source/WebCore
Revision
248366
Author
[email protected]
Date
2019-08-07 09:08:58 -0700 (Wed, 07 Aug 2019)

Log Message

ASSERT that a sessionID is valid when encoding it
https://bugs.webkit.org/show_bug.cgi?id=199302

Reviewed by Darin Adler.

Source/WebCore:

For IDBValue, instead of encoding an invalid session ID, encode a boolean that tells there is no sessionID.
For IDBRequestData, keep track of whether there is an IDBDatabaseIdentifier
and encode/decode accordingly to not encode an invalid sessionID.
No observable change of behavior.

* Modules/indexeddb/IDBValue.h:
(WebCore::IDBValue::sessionID const):
(WebCore::IDBValue::encode const):
(WebCore::IDBValue::decode):
* Modules/indexeddb/shared/IDBRequestData.cpp:
(WebCore::IDBRequestData::isolatedCopy):
* Modules/indexeddb/shared/IDBRequestData.h:
(WebCore::IDBRequestData::databaseIdentifier const):
(WebCore::IDBRequestData::decode):

Source/WebCore/PAL:

ASSERT that a sessionID is valid at encoding/decoding time.

* pal/SessionID.h:
(PAL::SessionID::encode const):
(PAL::SessionID::decode):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (248365 => 248366)


--- trunk/Source/WebCore/ChangeLog	2019-08-07 15:32:55 UTC (rev 248365)
+++ trunk/Source/WebCore/ChangeLog	2019-08-07 16:08:58 UTC (rev 248366)
@@ -1,3 +1,25 @@
+2019-08-07  Youenn Fablet  <[email protected]>
+
+        ASSERT that a sessionID is valid when encoding it
+        https://bugs.webkit.org/show_bug.cgi?id=199302
+
+        Reviewed by Darin Adler.
+
+        For IDBValue, instead of encoding an invalid session ID, encode a boolean that tells there is no sessionID.
+        For IDBRequestData, keep track of whether there is an IDBDatabaseIdentifier
+        and encode/decode accordingly to not encode an invalid sessionID.
+        No observable change of behavior.
+
+        * Modules/indexeddb/IDBValue.h:
+        (WebCore::IDBValue::sessionID const):
+        (WebCore::IDBValue::encode const):
+        (WebCore::IDBValue::decode):
+        * Modules/indexeddb/shared/IDBRequestData.cpp:
+        (WebCore::IDBRequestData::isolatedCopy):
+        * Modules/indexeddb/shared/IDBRequestData.h:
+        (WebCore::IDBRequestData::databaseIdentifier const):
+        (WebCore::IDBRequestData::decode):
+
 2019-08-07  Zalan Bujtas  <[email protected]>
 
         [LFC] Rename FormattingContext::layoutOutOfFlowDescendants to layoutOutOfFlowContent

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBValue.cpp (248365 => 248366)


--- trunk/Source/WebCore/Modules/indexeddb/IDBValue.cpp	2019-08-07 15:32:55 UTC (rev 248365)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBValue.cpp	2019-08-07 16:08:58 UTC (rev 248366)
@@ -40,8 +40,9 @@
 IDBValue::IDBValue(const SerializedScriptValue& scriptValue)
     : m_data(ThreadSafeDataBuffer::copyVector(scriptValue.data()))
     , m_blobURLs(scriptValue.blobURLsIsolatedCopy())
-    , m_sessionID(scriptValue.sessionID())
 {
+    if (scriptValue.sessionID().isValid())
+        m_sessionID = scriptValue.sessionID();
 }
 
 IDBValue::IDBValue(const ThreadSafeDataBuffer& value)
@@ -52,26 +53,29 @@
 IDBValue::IDBValue(const SerializedScriptValue& scriptValue, const Vector<String>& blobURLs, const PAL::SessionID& sessionID, const Vector<String>& blobFilePaths)
     : m_data(ThreadSafeDataBuffer::copyVector(scriptValue.data()))
     , m_blobURLs(blobURLs)
-    , m_sessionID(sessionID)
     , m_blobFilePaths(blobFilePaths)
 {
     ASSERT(m_data.data());
+    if (sessionID.isValid())
+        m_sessionID = sessionID;
 }
 
 IDBValue::IDBValue(const ThreadSafeDataBuffer& value, Vector<String>&& blobURLs, const PAL::SessionID& sessionID, Vector<String>&& blobFilePaths)
     : m_data(value)
     , m_blobURLs(WTFMove(blobURLs))
-    , m_sessionID(sessionID)
     , m_blobFilePaths(WTFMove(blobFilePaths))
 {
+    if (sessionID.isValid())
+        m_sessionID = sessionID;
 }
 
 IDBValue::IDBValue(const ThreadSafeDataBuffer& value, const Vector<String>& blobURLs, const PAL::SessionID& sessionID, const Vector<String>& blobFilePaths)
     : m_data(value)
     , m_blobURLs(blobURLs)
-    , m_sessionID(sessionID)
     , m_blobFilePaths(blobFilePaths)
 {
+    if (sessionID.isValid())
+        m_sessionID = sessionID;
 }
 
 void IDBValue::setAsIsolatedCopy(const IDBValue& other)

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBValue.h (248365 => 248366)


--- trunk/Source/WebCore/Modules/indexeddb/IDBValue.h	2019-08-07 15:32:55 UTC (rev 248365)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBValue.h	2019-08-07 16:08:58 UTC (rev 248366)
@@ -50,7 +50,7 @@
 
     const ThreadSafeDataBuffer& data() const { return m_data; }
     const Vector<String>& blobURLs() const { return m_blobURLs; }
-    const PAL::SessionID& sessionID() const { return m_sessionID; }
+    PAL::SessionID sessionID() const;
     const Vector<String>& blobFilePaths() const { return m_blobFilePaths; }
 
     template<class Encoder> void encode(Encoder&) const;
@@ -59,10 +59,17 @@
 private:
     ThreadSafeDataBuffer m_data;
     Vector<String> m_blobURLs;
-    PAL::SessionID m_sessionID;
+    Optional<PAL::SessionID> m_sessionID;
     Vector<String> m_blobFilePaths;
 };
 
+inline PAL::SessionID IDBValue::sessionID() const
+{
+    // FIXME: We should assert m_sessionID is valid or remove m_sessionID.
+    if (!m_sessionID)
+        return { };
+    return *m_sessionID;
+}
 
 template<class Encoder>
 void IDBValue::encode(Encoder& encoder) const

Modified: trunk/Source/WebCore/Modules/indexeddb/shared/IDBRequestData.cpp (248365 => 248366)


--- trunk/Source/WebCore/Modules/indexeddb/shared/IDBRequestData.cpp	2019-08-07 15:32:55 UTC (rev 248365)
+++ trunk/Source/WebCore/Modules/indexeddb/shared/IDBRequestData.cpp	2019-08-07 16:08:58 UTC (rev 248366)
@@ -98,7 +98,8 @@
     destination.m_requestedVersion = source.m_requestedVersion;
     destination.m_requestType = source.m_requestType;
 
-    destination.m_databaseIdentifier = source.m_databaseIdentifier.isolatedCopy();
+    if (source.m_databaseIdentifier)
+        destination.m_databaseIdentifier = source.m_databaseIdentifier->isolatedCopy();
 
     if (source.m_requestIdentifier)
         destination.m_requestIdentifier = std::make_unique<IDBResourceIdentifier>(*source.m_requestIdentifier);

Modified: trunk/Source/WebCore/Modules/indexeddb/shared/IDBRequestData.h (248365 => 248366)


--- trunk/Source/WebCore/Modules/indexeddb/shared/IDBRequestData.h	2019-08-07 15:32:55 UTC (rev 248365)
+++ trunk/Source/WebCore/Modules/indexeddb/shared/IDBRequestData.h	2019-08-07 16:08:58 UTC (rev 248366)
@@ -65,7 +65,7 @@
     IndexedDB::IndexRecordType indexRecordType() const;
     IDBResourceIdentifier cursorIdentifier() const;
 
-    const IDBDatabaseIdentifier& databaseIdentifier() const { return m_databaseIdentifier; }
+    const IDBDatabaseIdentifier& databaseIdentifier() const;
     uint64_t requestedVersion() const;
 
     bool isOpenRequest() const { return m_requestType == IndexedDB::RequestType::Open; }
@@ -89,12 +89,20 @@
     uint64_t m_indexIdentifier { 0 };
     IndexedDB::IndexRecordType m_indexRecordType;
 
-    IDBDatabaseIdentifier m_databaseIdentifier;
+    mutable Optional<IDBDatabaseIdentifier> m_databaseIdentifier;
     uint64_t m_requestedVersion { 0 };
 
     IndexedDB::RequestType m_requestType { IndexedDB::RequestType::Other };
 };
 
+inline const IDBDatabaseIdentifier& IDBRequestData::databaseIdentifier() const
+{
+    ASSERT(m_databaseIdentifier);
+    if (!m_databaseIdentifier)
+        m_databaseIdentifier = IDBDatabaseIdentifier { };
+    return *m_databaseIdentifier;
+}
+
 template<class Encoder>
 void IDBRequestData::encode(Encoder& encoder) const
 {
@@ -128,7 +136,7 @@
     if (!decoder.decode(request.m_indexIdentifier))
         return false;
 
-    Optional<IDBDatabaseIdentifier> databaseIdentifier;
+    Optional<Optional<IDBDatabaseIdentifier>> databaseIdentifier;
     decoder >> databaseIdentifier;
     if (!databaseIdentifier)
         return false;

Modified: trunk/Source/WebCore/PAL/ChangeLog (248365 => 248366)


--- trunk/Source/WebCore/PAL/ChangeLog	2019-08-07 15:32:55 UTC (rev 248365)
+++ trunk/Source/WebCore/PAL/ChangeLog	2019-08-07 16:08:58 UTC (rev 248366)
@@ -1,3 +1,16 @@
+2019-08-07  Youenn Fablet  <[email protected]>
+
+        ASSERT that a sessionID is valid when encoding it
+        https://bugs.webkit.org/show_bug.cgi?id=199302
+
+        Reviewed by Darin Adler.
+
+        ASSERT that a sessionID is valid at encoding/decoding time.
+
+        * pal/SessionID.h:
+        (PAL::SessionID::encode const):
+        (PAL::SessionID::decode):
+
 2019-08-06  Dean Jackson  <[email protected]>
 
         Context menu on a universal link produces a blank preview

Modified: trunk/Source/WebCore/PAL/pal/SessionID.h (248365 => 248366)


--- trunk/Source/WebCore/PAL/pal/SessionID.h	2019-08-07 15:32:55 UTC (rev 248365)
+++ trunk/Source/WebCore/PAL/pal/SessionID.h	2019-08-07 16:08:58 UTC (rev 248366)
@@ -80,7 +80,7 @@
 template<class Encoder>
 void SessionID::encode(Encoder& encoder) const
 {
-    // FIXME: Eliminate places that encode invalid SessionIDs, then ASSERT here that the sessionID is valid.
+    ASSERT(isValid());
     encoder << m_sessionID;
 }
 
@@ -104,7 +104,8 @@
     if (!sessionID)
         return WTF::nullopt;
 
-    // FIXME: Eliminate places that encode invalid SessionIDs, then fail to decode an invalid sessionID.
+    // FIXME: We should fail to decode an invalid sessionID.
+    ASSERT(SessionID { *sessionID }.isValid());
     return SessionID { *sessionID };
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to