Diff
Modified: trunk/Source/WebCore/ChangeLog (276677 => 276678)
--- trunk/Source/WebCore/ChangeLog 2021-04-27 23:01:41 UTC (rev 276677)
+++ trunk/Source/WebCore/ChangeLog 2021-04-27 23:35:22 UTC (rev 276678)
@@ -1,3 +1,17 @@
+2021-04-27 Chris Dumez <[email protected]>
+
+ IPC::decoder::decode() should mark decoder as invalid when failing
+ https://bugs.webkit.org/show_bug.cgi?id=225117
+
+ Reviewed by Darin Adler.
+
+ IPC::decoder::decode() should mark decoder as invalid when failing, instead of relying
+ on individual type decoders to do so. This makes type decoders a bit simpler and less
+ error-prone.
+
+ * Modules/highlight/AppHighlight.h:
+ (WebCore::AppHighlight::decode):
+
2021-04-27 Alex Christensen <[email protected]>
charset in contentType used in Blob.prototype.slice(start, end, contentType) is lost
Modified: trunk/Source/WebCore/Modules/highlight/AppHighlight.h (276677 => 276678)
--- trunk/Source/WebCore/Modules/highlight/AppHighlight.h 2021-04-27 23:01:41 UTC (rev 276677)
+++ trunk/Source/WebCore/Modules/highlight/AppHighlight.h 2021-04-27 23:35:22 UTC (rev 276678)
@@ -70,10 +70,8 @@
if (!length)
return WTF::nullopt;
- if (!decoder.template bufferIsLargeEnoughToContain<uint8_t>(length.value())) {
- decoder.markInvalid();
+ if (!decoder.template bufferIsLargeEnoughToContain<uint8_t>(length.value()))
return WTF::nullopt;
- }
Vector<uint8_t> highlight;
highlight.grow(*length);
Modified: trunk/Source/WebKit/ChangeLog (276677 => 276678)
--- trunk/Source/WebKit/ChangeLog 2021-04-27 23:01:41 UTC (rev 276677)
+++ trunk/Source/WebKit/ChangeLog 2021-04-27 23:35:22 UTC (rev 276678)
@@ -1,3 +1,35 @@
+2021-04-27 Chris Dumez <[email protected]>
+
+ IPC::decoder::decode() should mark decoder as invalid when failing
+ https://bugs.webkit.org/show_bug.cgi?id=225117
+
+ Reviewed by Darin Adler.
+
+ IPC::decoder::decode() should mark decoder as invalid when failing, instead of relying
+ on individual type decoders to do so. This makes type decoders a bit simpler and less
+ error-prone.
+
+ * Platform/IPC/ArgumentCoders.cpp:
+ (IPC::ArgumentCoder<CString>::decode):
+ (IPC::decodeStringText):
+ * Platform/IPC/ArgumentCoders.h:
+ * Platform/IPC/Connection.cpp:
+ (IPC::Connection::dispatchMessageReceiverMessage):
+ (IPC::Connection::dispatchSyncMessage):
+ * Platform/IPC/Decoder.cpp:
+ (IPC::m_destinationID):
+ * Platform/IPC/Decoder.h:
+ (IPC::Decoder::decode):
+ (IPC::Decoder::operator>>):
+ * Platform/IPC/HandleMessage.h:
+ (IPC::handleMessage):
+ (IPC::handleMessageSynchronous):
+ (IPC::handleMessageSynchronousWantsConnection):
+ (IPC::handleMessageAsync):
+ (IPC::handleMessageAsyncWantsConnection):
+ * WebProcess/Plugins/Plugin.cpp:
+ (WebKit::Plugin::Parameters::decode):
+
2021-04-27 Alex Christensen <[email protected]>
charset in contentType used in Blob.prototype.slice(start, end, contentType) is lost
Modified: trunk/Source/WebKit/Platform/IPC/ArgumentCoders.cpp (276677 => 276678)
--- trunk/Source/WebKit/Platform/IPC/ArgumentCoders.cpp 2021-04-27 23:01:41 UTC (rev 276677)
+++ trunk/Source/WebKit/Platform/IPC/ArgumentCoders.cpp 2021-04-27 23:35:22 UTC (rev 276678)
@@ -98,10 +98,8 @@
}
// Before allocating the string, make sure that the decoder buffer is big enough.
- if (!decoder.bufferIsLargeEnoughToContain<char>(length)) {
- decoder.markInvalid();
+ if (!decoder.bufferIsLargeEnoughToContain<char>(length))
return false;
- }
char* buffer;
CString string = CString::newUninitialized(length, buffer);
@@ -140,10 +138,8 @@
static inline Optional<String> decodeStringText(Decoder& decoder, uint32_t length)
{
// Before allocating the string, make sure that the decoder buffer is big enough.
- if (!decoder.bufferIsLargeEnoughToContain<CharacterType>(length)) {
- decoder.markInvalid();
+ if (!decoder.bufferIsLargeEnoughToContain<CharacterType>(length))
return WTF::nullopt;
- }
CharacterType* buffer;
String string = String::createUninitialized(length, buffer);
Modified: trunk/Source/WebKit/Platform/IPC/ArgumentCoders.h (276677 => 276678)
--- trunk/Source/WebKit/Platform/IPC/ArgumentCoders.h 2021-04-27 23:01:41 UTC (rev 276677)
+++ trunk/Source/WebKit/Platform/IPC/ArgumentCoders.h 2021-04-27 23:35:22 UTC (rev 276678)
@@ -428,15 +428,11 @@
static WARN_UNUSED_RETURN bool decode(Decoder& decoder, Vector<T, inlineCapacity, OverflowHandler, minCapacity>& vector)
{
uint64_t decodedSize;
- if (!decoder.decode(decodedSize)) {
- decoder.markInvalid();
+ if (!decoder.decode(decodedSize))
return false;
- }
- if (!isInBounds<size_t>(decodedSize)) {
- decoder.markInvalid();
+ if (!isInBounds<size_t>(decodedSize))
return false;
- }
auto size = static_cast<size_t>(decodedSize);
@@ -443,18 +439,14 @@
// Since we know the total size of the elements, we can allocate the vector in
// one fell swoop. Before allocating we must however make sure that the decoder buffer
// is big enough.
- if (!decoder.bufferIsLargeEnoughToContain<T>(size)) {
- decoder.markInvalid();
+ if (!decoder.bufferIsLargeEnoughToContain<T>(size))
return false;
- }
Vector<T, inlineCapacity, OverflowHandler, minCapacity> temp;
temp.grow(size);
- if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(temp.data()), size * sizeof(T), alignof(T))) {
- decoder.markInvalid();
+ if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(temp.data()), size * sizeof(T), alignof(T)))
return false;
- }
vector.swap(temp);
return true;
@@ -463,15 +455,11 @@
static Optional<Vector<T, inlineCapacity, OverflowHandler, minCapacity>> decode(Decoder& decoder)
{
uint64_t decodedSize;
- if (!decoder.decode(decodedSize)) {
- decoder.markInvalid();
+ if (!decoder.decode(decodedSize))
return WTF::nullopt;
- }
- if (!isInBounds<size_t>(decodedSize)) {
- decoder.markInvalid();
+ if (!isInBounds<size_t>(decodedSize))
return WTF::nullopt;
- }
auto size = static_cast<size_t>(decodedSize);
@@ -478,18 +466,14 @@
// Since we know the total size of the elements, we can allocate the vector in
// one fell swoop. Before allocating we must however make sure that the decoder buffer
// is big enough.
- if (!decoder.bufferIsLargeEnoughToContain<T>(size)) {
- decoder.markInvalid();
+ if (!decoder.bufferIsLargeEnoughToContain<T>(size))
return WTF::nullopt;
- }
Vector<T, inlineCapacity, OverflowHandler, minCapacity> vector;
vector.grow(size);
- if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(vector.data()), size * sizeof(T), alignof(T))) {
- decoder.markInvalid();
+ if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(vector.data()), size * sizeof(T), alignof(T)))
return WTF::nullopt;
- }
return vector;
}
@@ -525,14 +509,11 @@
if (UNLIKELY(!value))
return WTF::nullopt;
- if (UNLIKELY(!HashMapType::isValidKey(*key))) {
- decoder.markInvalid();
+ if (UNLIKELY(!HashMapType::isValidKey(*key)))
return WTF::nullopt;
- }
if (UNLIKELY(!hashMap.add(WTFMove(*key), WTFMove(*value)).isNewEntry)) {
// The hash map already has the specified key, bail.
- decoder.markInvalid();
return WTF::nullopt;
}
}
@@ -585,14 +566,11 @@
if (!key)
return WTF::nullopt;
- if (UNLIKELY(!HashSetType::isValidValue(*key))) {
- decoder.markInvalid();
+ if (UNLIKELY(!HashSetType::isValidValue(*key)))
return WTF::nullopt;
- }
if (UNLIKELY(!hashSet.add(WTFMove(*key)).isNewEntry)) {
// The hash set already has the specified key, bail.
- decoder.markInvalid();
return WTF::nullopt;
}
}
@@ -630,14 +608,11 @@
if (!decoder.decode(count))
return false;
- if (UNLIKELY(!HashCountedSetType::isValidValue(key))) {
- decoder.markInvalid();
+ if (UNLIKELY(!HashCountedSetType::isValidValue(key)))
return false;
- }
if (UNLIKELY(!tempHashCountedSet.add(key, count).isNewEntry)) {
// The hash counted set already has the specified key, bail.
- decoder.markInvalid();
return false;
}
}
Modified: trunk/Source/WebKit/Platform/IPC/Connection.cpp (276677 => 276678)
--- trunk/Source/WebKit/Platform/IPC/Connection.cpp 2021-04-27 23:01:41 UTC (rev 276677)
+++ trunk/Source/WebKit/Platform/IPC/Connection.cpp 2021-04-27 23:35:22 UTC (rev 276678)
@@ -34,6 +34,7 @@
#include <wtf/HashSet.h>
#include <wtf/Lock.h>
#include <wtf/NeverDestroyed.h>
+#include <wtf/ObjectIdentifier.h>
#include <wtf/RunLoop.h>
#include <wtf/text/WTFString.h>
#include <wtf/threads/BinarySemaphore.h>
@@ -235,7 +236,7 @@
// Represents a sync request for which we're waiting on a reply.
struct Connection::PendingSyncReply {
// The request ID.
- uint64_t syncRequestID { 0 };
+ Connection::SyncRequestID syncRequestID;
// The reply decoder, will be null if there was an error processing the sync
// message on the other side.
@@ -246,7 +247,7 @@
PendingSyncReply() = default;
- explicit PendingSyncReply(uint64_t syncRequestID)
+ explicit PendingSyncReply(Connection::SyncRequestID syncRequestID)
: syncRequestID(syncRequestID)
{
}
@@ -287,7 +288,6 @@
: m_client(client)
, m_uniqueID(UniqueID::generate())
, m_isServer(isServer)
- , m_syncRequestID(0)
, m_onlySendMessagesAsDispatchWhenWaitingForSyncReplyWhenProcessingSuchAMessage(false)
, m_shouldExitOnSyncMessageSendFailure(false)
, m_didCloseOnConnectionWorkQueueCallback(0)
@@ -390,15 +390,14 @@
return;
}
- uint64_t syncRequestID = 0;
- if (!decoder->decode(syncRequestID) || !syncRequestID) {
+ SyncRequestID syncRequestID;
+ if (UNLIKELY(!decoder->decode(syncRequestID))) {
// We received an invalid sync message.
// FIXME: Handle this.
- decoder->markInvalid();
return;
}
- auto replyEncoder = makeUniqueRef<Encoder>(MessageName::SyncMessageReply, syncRequestID);
+ auto replyEncoder = makeUniqueRef<Encoder>(MessageName::SyncMessageReply, syncRequestID.toUInt64());
// Hand off both the decoder and encoder to the work queue message receiver.
bool wasHandled = messageReceiver.didReceiveSyncMessage(*this, *decoder, replyEncoder);
@@ -441,7 +440,7 @@
m_didReceiveInvalidMessage = true;
}
-UniqueRef<Encoder> Connection::createSyncMessageEncoder(MessageName messageName, uint64_t destinationID, uint64_t& syncRequestID)
+UniqueRef<Encoder> Connection::createSyncMessageEncoder(MessageName messageName, uint64_t destinationID, SyncRequestID& syncRequestID)
{
auto encoder = makeUniqueRef<Encoder>(messageName, destinationID);
@@ -472,7 +471,7 @@
#endif
if (isMainRunLoop() && m_inDispatchMessageMarkedToUseFullySynchronousModeForTesting && !encoder->isSyncMessage() && !(encoder->messageReceiverName() == ReceiverName::IPC) && !sendOptions.contains(SendOption::IgnoreFullySynchronousMode)) {
- uint64_t syncRequestID;
+ SyncRequestID syncRequestID;
auto wrappedMessage = createSyncMessageEncoder(MessageName::WrappedAsyncMessageForTesting, encoder->destinationID(), syncRequestID);
wrappedMessage->setFullySynchronousModeForTesting();
wrappedMessage->wrapForTesting(WTFMove(encoder));
@@ -590,7 +589,7 @@
return nullptr;
}
-bool Connection::pushPendingSyncRequestID(uint64_t syncRequestID)
+bool Connection::pushPendingSyncRequestID(SyncRequestID syncRequestID)
{
{
LockHolder locker(m_syncReplyStateMutex);
@@ -602,7 +601,7 @@
return true;
}
-void Connection::popPendingSyncRequestID(uint64_t syncRequestID)
+void Connection::popPendingSyncRequestID(SyncRequestID syncRequestID)
{
--m_inSendSyncCount;
LockHolder locker(m_syncReplyStateMutex);
@@ -610,7 +609,7 @@
m_pendingSyncReplies.removeLast();
}
-std::unique_ptr<Decoder> Connection::sendSyncMessage(uint64_t syncRequestID, UniqueRef<Encoder>&& encoder, Timeout timeout, OptionSet<SendSyncOption> sendSyncOptions)
+std::unique_ptr<Decoder> Connection::sendSyncMessage(SyncRequestID syncRequestID, UniqueRef<Encoder>&& encoder, Timeout timeout, OptionSet<SendSyncOption> sendSyncOptions)
{
ASSERT(syncRequestID);
ASSERT(RunLoop::isMain());
@@ -648,7 +647,7 @@
return reply;
}
-std::unique_ptr<Decoder> Connection::waitForSyncReply(uint64_t syncRequestID, MessageName messageName, Timeout timeout, OptionSet<SendSyncOption> sendSyncOptions)
+std::unique_ptr<Decoder> Connection::waitForSyncReply(SyncRequestID syncRequestID, MessageName messageName, Timeout timeout, OptionSet<SendSyncOption> sendSyncOptions)
{
timeout = timeoutRespectingIgnoreTimeoutsForTesting(timeout);
@@ -680,7 +679,7 @@
// If that happens, we need to stop waiting, or we'll hang since we won't get
// any more incoming messages.
if (!isValid()) {
- RELEASE_LOG_ERROR(IPC, "Connection::waitForSyncReply: Connection no longer valid, id=%" PRIu64, syncRequestID);
+ RELEASE_LOG_ERROR(IPC, "Connection::waitForSyncReply: Connection no longer valid, id=%" PRIu64, syncRequestID.toUInt64());
didReceiveSyncReply(sendSyncOptions);
return nullptr;
}
@@ -692,9 +691,9 @@
}
#if OS(DARWIN)
- RELEASE_LOG_ERROR(IPC, "Connection::waitForSyncReply: Timed-out while waiting for reply for %{public}s from process %d, id=%" PRIu64, description(messageName), remoteProcessID(), syncRequestID);
+ RELEASE_LOG_ERROR(IPC, "Connection::waitForSyncReply: Timed-out while waiting for reply for %{public}s from process %d, id=%" PRIu64, description(messageName), remoteProcessID(), syncRequestID.toUInt64());
#else
- RELEASE_LOG_ERROR(IPC, "Connection::waitForSyncReply: Timed-out while waiting for reply for %s, id=%" PRIu64, description(messageName), syncRequestID);
+ RELEASE_LOG_ERROR(IPC, "Connection::waitForSyncReply: Timed-out while waiting for reply for %s, id=%" PRIu64, description(messageName), syncRequestID.toUInt64());
#endif
didReceiveSyncReply(sendSyncOptions);
@@ -712,7 +711,7 @@
for (size_t i = m_pendingSyncReplies.size(); i > 0; --i) {
PendingSyncReply& pendingSyncReply = m_pendingSyncReplies[i - 1];
- if (pendingSyncReply.syncRequestID != decoder->destinationID())
+ if (pendingSyncReply.syncRequestID.toUInt64() != decoder->destinationID())
continue;
ASSERT(!pendingSyncReply.replyDecoder);
@@ -926,14 +925,13 @@
{
ASSERT(decoder.isSyncMessage());
- uint64_t syncRequestID = 0;
- if (!decoder.decode(syncRequestID) || !syncRequestID) {
+ SyncRequestID syncRequestID;
+ if (UNLIKELY(!decoder.decode(syncRequestID))) {
// We received an invalid sync message.
- decoder.markInvalid();
return;
}
- auto replyEncoder = makeUniqueRef<Encoder>(MessageName::SyncMessageReply, syncRequestID);
+ auto replyEncoder = makeUniqueRef<Encoder>(MessageName::SyncMessageReply, syncRequestID.toUInt64());
bool wasHandled = false;
if (decoder.messageName() == MessageName::WrappedAsyncMessageForTesting) {
Modified: trunk/Source/WebKit/Platform/IPC/Connection.h (276677 => 276678)
--- trunk/Source/WebKit/Platform/IPC/Connection.h 2021-04-27 23:01:41 UTC (rev 276677)
+++ trunk/Source/WebKit/Platform/IPC/Connection.h 2021-04-27 23:35:22 UTC (rev 276678)
@@ -106,6 +106,9 @@
class Connection : public ThreadSafeRefCounted<Connection, WTF::DestructionThread::MainRunLoop> {
public:
+ enum SyncRequestIDType { };
+ using SyncRequestID = ObjectIdentifier<SyncRequestIDType>;
+
class Client : public MessageReceiver {
public:
virtual void didClose(Connection&) = 0;
@@ -276,8 +279,8 @@
}
bool sendMessage(UniqueRef<Encoder>&&, OptionSet<SendOption> sendOptions);
- UniqueRef<Encoder> createSyncMessageEncoder(MessageName, uint64_t destinationID, uint64_t& syncRequestID);
- std::unique_ptr<Decoder> sendSyncMessage(uint64_t syncRequestID, UniqueRef<Encoder>&&, Timeout, OptionSet<SendSyncOption> sendSyncOptions);
+ UniqueRef<Encoder> createSyncMessageEncoder(MessageName, uint64_t destinationID, SyncRequestID&);
+ std::unique_ptr<Decoder> sendSyncMessage(SyncRequestID, UniqueRef<Encoder>&&, Timeout, OptionSet<SendSyncOption> sendSyncOptions);
bool sendSyncReply(UniqueRef<Encoder>&&);
void wakeUpRunLoop();
@@ -324,11 +327,12 @@
bool isIncomingMessagesThrottlingEnabled() const { return !!m_incomingMessagesThrottler; }
std::unique_ptr<Decoder> waitForMessage(MessageName, uint64_t destinationID, Timeout, OptionSet<WaitForOption>);
- uint64_t makeSyncRequestID() { return ++m_syncRequestID; }
- bool pushPendingSyncRequestID(uint64_t syncRequestID);
- void popPendingSyncRequestID(uint64_t syncRequestID);
- std::unique_ptr<Decoder> waitForSyncReply(uint64_t syncRequestID, MessageName, Timeout, OptionSet<SendSyncOption>);
+ SyncRequestID makeSyncRequestID() { return SyncRequestID::generateThreadSafe(); }
+ bool pushPendingSyncRequestID(SyncRequestID);
+ void popPendingSyncRequestID(SyncRequestID);
+ std::unique_ptr<Decoder> waitForSyncReply(SyncRequestID, MessageName, Timeout, OptionSet<SendSyncOption>);
+
void enqueueMatchingMessagesToMessageReceiveQueue(Locker<Lock>& incomingMessagesLocker, MessageReceiveQueue&, ReceiverName, uint64_t destinationID);
// Called on the connection work queue.
@@ -382,7 +386,6 @@
UniqueID m_uniqueID;
bool m_isServer;
std::atomic<bool> m_isValid { true };
- std::atomic<uint64_t> m_syncRequestID;
bool m_onlySendMessagesAsDispatchWhenWaitingForSyncReplyWhenProcessingSuchAMessage;
bool m_shouldExitOnSyncMessageSendFailure;
@@ -558,7 +561,7 @@
COMPILE_ASSERT(T::isSync, SyncMessageExpected);
RELEASE_ASSERT(RunLoop::isMain());
- uint64_t syncRequestID = 0;
+ SyncRequestID syncRequestID;
auto encoder = createSyncMessageEncoder(T::name(), destinationID, syncRequestID);
if (sendSyncOptions.contains(SendSyncOption::UseFullySynchronousModeForTesting)) {
Modified: trunk/Source/WebKit/Platform/IPC/Decoder.cpp (276677 => 276678)
--- trunk/Source/WebKit/Platform/IPC/Decoder.cpp 2021-04-27 23:01:41 UTC (rev 276677)
+++ trunk/Source/WebKit/Platform/IPC/Decoder.cpp 2021-04-27 23:35:22 UTC (rev 276678)
@@ -79,25 +79,19 @@
, m_bufferDeallocator { bufferDeallocator }
, m_attachments { WTFMove(attachments) }
{
- if (reinterpret_cast<uintptr_t>(m_buffer) % alignof(uint64_t)) {
+ if (UNLIKELY(reinterpret_cast<uintptr_t>(m_buffer) % alignof(uint64_t))) {
markInvalid();
return;
}
- if (!decode(m_messageFlags)) {
- markInvalid();
+ if (UNLIKELY(!decode(m_messageFlags)))
return;
- }
- if (!decode(m_messageName)) {
- markInvalid();
+ if (UNLIKELY(!decode(m_messageName)))
return;
- }
- if (!decode(m_destinationID)) {
- markInvalid();
+ if (UNLIKELY(!decode(m_destinationID)))
return;
- }
}
Decoder::Decoder(const uint8_t* buffer, size_t bufferSize, ConstructWithoutHeaderTag)
@@ -106,7 +100,7 @@
, m_bufferEnd { m_buffer + bufferSize }
, m_bufferDeallocator([] (const uint8_t*, size_t) { })
{
- if (reinterpret_cast<uintptr_t>(m_buffer) % alignof(uint64_t))
+ if (UNLIKELY(reinterpret_cast<uintptr_t>(m_buffer) % alignof(uint64_t)))
markInvalid();
}
@@ -117,10 +111,8 @@
, m_bufferDeallocator([] (const uint8_t*, size_t) { })
, m_destinationID(destinationID)
{
- if (!decode(m_messageName)) {
- markInvalid();
+ if (UNLIKELY(!decode(m_messageName)))
return;
- }
}
Decoder::~Decoder()
@@ -199,7 +191,7 @@
bool Decoder::alignBufferPosition(size_t alignment, size_t size)
{
const uint8_t* alignedPosition = roundUpToAlignment(m_bufferPos, alignment);
- if (!alignedBufferIsLargeEnoughToContain(alignedPosition, m_buffer, m_bufferEnd, size)) {
+ if (UNLIKELY(!alignedBufferIsLargeEnoughToContain(alignedPosition, m_buffer, m_bufferEnd, size))) {
// We've walked off the end of this buffer.
markInvalid();
return false;
Modified: trunk/Source/WebKit/Platform/IPC/Decoder.h (276677 => 276678)
--- trunk/Source/WebKit/Platform/IPC/Decoder.h 2021-04-27 23:01:41 UTC (rev 276677)
+++ trunk/Source/WebKit/Platform/IPC/Decoder.h 2021-04-27 23:35:22 UTC (rev 276678)
@@ -89,16 +89,21 @@
WARN_UNUSED_RETURN bool decode(T& t)
{
using Impl = ArgumentCoder<std::remove_const_t<std::remove_reference_t<T>>, void>;
- if constexpr(HasLegacyDecoder<T, Impl>::value)
- return Impl::decode(*this, t);
- else {
+ if constexpr(HasLegacyDecoder<T, Impl>::value) {
+ if (UNLIKELY(!Impl::decode(*this, t))) {
+ markInvalid();
+ return false;
+ }
+ } else {
Optional<T> optional;
*this >> optional;
- if (!optional)
+ if (UNLIKELY(!optional)) {
+ markInvalid();
return false;
+ }
t = WTFMove(*optional);
- return true;
}
+ return true;
}
template<typename T>
@@ -105,12 +110,16 @@
Decoder& operator>>(Optional<T>& t)
{
using Impl = ArgumentCoder<std::remove_const_t<std::remove_reference_t<T>>, void>;
- if constexpr(HasModernDecoder<T, Impl>::value)
+ if constexpr(HasModernDecoder<T, Impl>::value) {
t = Impl::decode(*this);
- else {
+ if (UNLIKELY(!t))
+ markInvalid();
+ } else {
T v;
- if (Impl::decode(*this, v))
+ if (LIKELY(Impl::decode(*this, v)))
t = WTFMove(v);
+ else
+ markInvalid();
}
return *this;
}
Modified: trunk/Source/WebKit/Platform/IPC/HandleMessage.h (276677 => 276678)
--- trunk/Source/WebKit/Platform/IPC/HandleMessage.h 2021-04-27 23:01:41 UTC (rev 276677)
+++ trunk/Source/WebKit/Platform/IPC/HandleMessage.h 2021-04-27 23:35:22 UTC (rev 276678)
@@ -113,10 +113,8 @@
{
Optional<typename CodingType<typename T::Arguments>::Type> arguments;
decoder >> arguments;
- if (!arguments) {
- decoder.markInvalid();
+ if (UNLIKELY(!arguments))
return;
- }
callMemberFunction(WTFMove(*arguments), object, function);
}
@@ -126,10 +124,8 @@
{
Optional<typename CodingType<typename T::Arguments>::Type> arguments;
decoder >> arguments;
- if (!arguments) {
- decoder.markInvalid();
+ if (UNLIKELY(!arguments))
return;
- }
callMemberFunction(connection, WTFMove(*arguments), object, function);
}
@@ -138,10 +134,8 @@
{
Optional<typename CodingType<typename T::Arguments>::Type> arguments;
decoder >> arguments;
- if (!arguments) {
- decoder.markInvalid();
+ if (UNLIKELY(!arguments))
return false;
- }
typename T::DelayedReply completionHandler = [replyEncoder = WTFMove(replyEncoder), connection = makeRef(connection)] (auto&&... args) mutable {
T::send(WTFMove(replyEncoder), WTFMove(connection), args...);
@@ -155,10 +149,8 @@
{
Optional<typename CodingType<typename T::Arguments>::Type> arguments;
decoder >> arguments;
- if (!arguments) {
- decoder.markInvalid();
+ if (UNLIKELY(!arguments))
return false;
- }
typename T::DelayedReply completionHandler = [replyEncoder = WTFMove(replyEncoder), connection = makeRef(connection)] (auto&&... args) mutable {
T::send(WTFMove(replyEncoder), WTFMove(connection), args...);
@@ -170,18 +162,14 @@
template<typename T, typename C, typename MF>
void handleMessageSynchronous(StreamServerConnectionBase& connection, Decoder& decoder, C* object, MF function)
{
- uint64_t syncRequestID = 0;
- if (!decoder.decode(syncRequestID) || !syncRequestID) {
- decoder.markInvalid();
+ Connection::SyncRequestID syncRequestID;
+ if (UNLIKELY(!decoder.decode(syncRequestID)))
return;
- }
Optional<typename CodingType<typename T::Arguments>::Type> arguments;
decoder >> arguments;
- if (!arguments) {
- decoder.markInvalid();
+ if (UNLIKELY(!arguments))
return;
- }
typename T::DelayedReply completionHandler = [syncRequestID, connection = makeRef(connection)] (auto&&... args) mutable {
connection->sendSyncReply<T>(syncRequestID, args...);
@@ -194,17 +182,13 @@
{
Optional<uint64_t> listenerID;
decoder >> listenerID;
- if (!listenerID) {
- decoder.markInvalid();
+ if (!listenerID)
return;
- }
Optional<typename CodingType<typename T::Arguments>::Type> arguments;
decoder >> arguments;
- if (!arguments) {
- decoder.markInvalid();
+ if (UNLIKELY(!arguments))
return;
- }
typename T::AsyncReply completionHandler = { [listenerID = *listenerID, connection = makeRef(connection)] (auto&&... args) mutable {
auto encoder = makeUniqueRef<Encoder>(T::asyncMessageReplyName(), listenerID);
@@ -218,10 +202,8 @@
{
Optional<typename CodingType<typename T::Arguments>::Type> arguments;
decoder >> arguments;
- if (!arguments) {
- decoder.markInvalid();
+ if (UNLIKELY(!arguments))
return;
- }
typename T::AsyncReply completionHandler = [listenerID = decoder.destinationID(), connection = makeRef(connection)] (auto&&... args) mutable {
auto encoder = makeUniqueRef<Encoder>(T::asyncMessageReplyName(), listenerID);
Modified: trunk/Source/WebKit/Platform/IPC/StreamServerConnection.h (276677 => 276678)
--- trunk/Source/WebKit/Platform/IPC/StreamServerConnection.h 2021-04-27 23:01:41 UTC (rev 276677)
+++ trunk/Source/WebKit/Platform/IPC/StreamServerConnection.h 2021-04-27 23:35:22 UTC (rev 276678)
@@ -53,7 +53,7 @@
virtual DispatchResult dispatchStreamMessages(size_t messageLimit) = 0;
template<typename T, typename... Arguments>
- void sendSyncReply(uint64_t syncRequestID, Arguments&&...);
+ void sendSyncReply(Connection::SyncRequestID, Arguments&&...);
protected:
StreamServerConnectionBase(IPC::Connection&, StreamConnectionBuffer&&, StreamConnectionWorkQueue&);
@@ -102,7 +102,7 @@
};
template<typename T, typename... Arguments>
-void StreamServerConnectionBase::sendSyncReply(uint64_t syncRequestID, Arguments&&... arguments)
+void StreamServerConnectionBase::sendSyncReply(Connection::SyncRequestID syncRequestID, Arguments&&... arguments)
{
if constexpr(T::isReplyStreamEncodable) {
if (m_isDispatchingStreamMessage) {
@@ -115,7 +115,7 @@
StreamConnectionEncoder outOfStreamEncoder { MessageName::ProcessOutOfStreamMessage, span.data, span.size };
}
}
- auto encoder = makeUniqueRef<Encoder>(MessageName::SyncMessageReply, syncRequestID);
+ auto encoder = makeUniqueRef<Encoder>(MessageName::SyncMessageReply, syncRequestID.toUInt64());
(encoder.get() << ... << arguments);
m_connection->sendSyncReply(WTFMove(encoder));
Modified: trunk/Source/WebKit/WebProcess/Plugins/Plugin.cpp (276677 => 276678)
--- trunk/Source/WebKit/WebProcess/Plugins/Plugin.cpp 2021-04-27 23:01:41 UTC (rev 276677)
+++ trunk/Source/WebKit/WebProcess/Plugins/Plugin.cpp 2021-04-27 23:35:22 UTC (rev 276678)
@@ -73,10 +73,8 @@
if (!decoder.decode(parameters.layerHostingMode))
return false;
#endif
- if (parameters.names.size() != parameters.values.size()) {
- decoder.markInvalid();
+ if (parameters.names.size() != parameters.values.size())
return false;
- }
return true;
}
Modified: trunk/Source/WebKit/WebProcess/WebPage/IPCTestingAPI.cpp (276677 => 276678)
--- trunk/Source/WebKit/WebProcess/WebPage/IPCTestingAPI.cpp 2021-04-27 23:01:41 UTC (rev 276677)
+++ trunk/Source/WebKit/WebProcess/WebPage/IPCTestingAPI.cpp 2021-04-27 23:35:22 UTC (rev 276678)
@@ -737,7 +737,7 @@
// FIXME: Support the options.
- uint64_t syncRequestID = 0;
+ IPC::Connection::SyncRequestID syncRequestID;
auto messageName = static_cast<IPC::MessageName>(*messageID);
auto encoder = connection->createSyncMessageEncoder(messageName, *destinationID, syncRequestID);
@@ -970,8 +970,9 @@
RETURN_IF_EXCEPTION(scope, nullptr);
if (decoder.isSyncMessage()) {
- if (uint64_t syncRequestID = 0; decoder.decode(syncRequestID)) {
- jsResult->putDirect(vm, JSC::Identifier::fromString(vm, "syncRequestID"), JSC::JSValue(syncRequestID));
+ IPC::Connection::SyncRequestID syncRequestID;
+ if (decoder.decode(syncRequestID)) {
+ jsResult->putDirect(vm, JSC::Identifier::fromString(vm, "syncRequestID"), JSC::JSValue(syncRequestID.toUInt64()));
RETURN_IF_EXCEPTION(scope, nullptr);
}
} else if (messageReplyArgumentDescriptions(decoder.messageName())) {