Title: [292209] trunk/Source/WebKit
Revision
292209
Author
timothy_hor...@apple.com
Date
2022-04-01 01:26:21 -0700 (Fri, 01 Apr 2022)

Log Message

Translated applications cannot use remote methods with BOOL arguments
https://bugs.webkit.org/show_bug.cgi?id=238651
<rdar://90509457>

Reviewed by Geoffrey Garen.

Propagate the fix from r261155 to WKRemoteObjectCoder's method-signature-equality test as well,
so that BOOL arguments correctly compare as equal between a Rosetta application and its
native ARM Web Content process.

* Shared/API/Cocoa/WKRemoteObjectCoder.h:
* Shared/API/Cocoa/WKRemoteObjectCoder.mm:
(WebKit::methodSignaturesAreCompatible):
(decodeInvocation):
Relax argument signature validation slightly, considering signed char and BOOL,
which are equivalent and sometimes substituted for each other, to be equal.

* Shared/API/Cocoa/_WKRemoteObjectRegistry.mm:
(-[_WKRemoteObjectRegistry _invokeMethod:]):
(blockSignaturesAreCompatible): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (292208 => 292209)


--- trunk/Source/WebKit/ChangeLog	2022-04-01 08:17:36 UTC (rev 292208)
+++ trunk/Source/WebKit/ChangeLog	2022-04-01 08:26:21 UTC (rev 292209)
@@ -1,5 +1,28 @@
 2022-04-01  Tim Horton  <timothy_hor...@apple.com>
 
+        Translated applications cannot use remote methods with BOOL arguments
+        https://bugs.webkit.org/show_bug.cgi?id=238651
+        <rdar://90509457>
+
+        Reviewed by Geoffrey Garen.
+
+        Propagate the fix from r261155 to WKRemoteObjectCoder's method-signature-equality test as well,
+        so that BOOL arguments correctly compare as equal between a Rosetta application and its
+        native ARM Web Content process.
+
+        * Shared/API/Cocoa/WKRemoteObjectCoder.h:
+        * Shared/API/Cocoa/WKRemoteObjectCoder.mm:
+        (WebKit::methodSignaturesAreCompatible):
+        (decodeInvocation):
+        Relax argument signature validation slightly, considering signed char and BOOL,
+        which are equivalent and sometimes substituted for each other, to be equal.
+
+        * Shared/API/Cocoa/_WKRemoteObjectRegistry.mm:
+        (-[_WKRemoteObjectRegistry _invokeMethod:]):
+        (blockSignaturesAreCompatible): Deleted.
+
+2022-04-01  Tim Horton  <timothy_hor...@apple.com>
+
         Add a debug overlay for interaction regions
         https://bugs.webkit.org/show_bug.cgi?id=238187
 

Modified: trunk/Source/WebKit/Shared/API/Cocoa/WKRemoteObjectCoder.h (292208 => 292209)


--- trunk/Source/WebKit/Shared/API/Cocoa/WKRemoteObjectCoder.h	2022-04-01 08:17:36 UTC (rev 292208)
+++ trunk/Source/WebKit/Shared/API/Cocoa/WKRemoteObjectCoder.h	2022-04-01 08:26:21 UTC (rev 292209)
@@ -42,3 +42,7 @@
 - (id)initWithInterface:(_WKRemoteObjectInterface *)interface rootObjectDictionary:(const API::Dictionary*)rootObjectDictionary replyToSelector:(SEL)replyToSelector;
 
 @end
+
+namespace WebKit {
+bool methodSignaturesAreCompatible(const String&, const String&);
+}

Modified: trunk/Source/WebKit/Shared/API/Cocoa/WKRemoteObjectCoder.mm (292208 => 292209)


--- trunk/Source/WebKit/Shared/API/Cocoa/WKRemoteObjectCoder.mm	2022-04-01 08:17:36 UTC (rev 292208)
+++ trunk/Source/WebKit/Shared/API/Cocoa/WKRemoteObjectCoder.mm	2022-04-01 08:26:21 UTC (rev 292209)
@@ -52,6 +52,33 @@
 
 static RefPtr<API::Dictionary> createEncodedObject(WKRemoteObjectEncoder *, id);
 
+namespace WebKit {
+
+bool methodSignaturesAreCompatible(const String& wire, const String& local)
+{
+    if (local == wire)
+        return true;
+
+    if (local.length() != wire.length())
+        return false;
+
+    unsigned length = local.length();
+    for (unsigned i = 0; i < length; i++) {
+        char localType = local[i];
+        char wireType = wire[i];
+
+        if (localType != wireType) {
+            // `bool` and `signed char` are interchangeable.
+            if (strchr("Bc", localType) && strchr("Bc", wireType))
+                continue;
+            return false;
+        }
+    }
+    return true;
+}
+
+}
+
 @interface NSMethodSignature ()
 - (NSString *)_typeString;
 @end
@@ -943,9 +970,10 @@
     if (!typeSignature)
         [NSException raise:NSInvalidUnarchiveOperationException format:@"Invocation had no type signature"];
 
-    NSMethodSignature *remoteMethodSignature = [NSMethodSignature signatureWithObjCTypes:typeSignature.UTF8String];
-    if (![[invocation methodSignature] isEqual:remoteMethodSignature])
-        [NSException raise:NSInvalidUnarchiveOperationException format:@"Local and remote method signatures are not equal for method \"%s\"", selector ? sel_getName(selector) : "(no selector)"];
+    String remoteMethodSignature = typeSignature.UTF8String;
+    String localMethodSignature = [invocation methodSignature]._typeString.UTF8String;
+    if (!WebKit::methodSignaturesAreCompatible(remoteMethodSignature, localMethodSignature))
+        [NSException raise:NSInvalidUnarchiveOperationException format:@"Local and remote method signatures are not compatible for method \"%s\"", selector ? sel_getName(selector) : "(no selector)"];
 
     if (isReplyBlock) {
         const auto& allowedClasses = [decoder->_interface _allowedArgumentClassesForReplyBlockOfSelector:decoder->_replyToSelector];

Modified: trunk/Source/WebKit/Shared/API/Cocoa/_WKRemoteObjectRegistry.mm (292208 => 292209)


--- trunk/Source/WebKit/Shared/API/Cocoa/_WKRemoteObjectRegistry.mm	2022-04-01 08:17:36 UTC (rev 292208)
+++ trunk/Source/WebKit/Shared/API/Cocoa/_WKRemoteObjectRegistry.mm	2022-04-01 08:26:21 UTC (rev 292209)
@@ -187,29 +187,6 @@
     return *_remoteObjectRegistry;
 }
 
-static bool blockSignaturesAreCompatible(const String& wire, const String& local)
-{
-    if (local == wire)
-        return true;
-
-    if (local.length() != wire.length())
-        return false;
-
-    unsigned length = local.length();
-    for (unsigned i = 0; i < length; i++) {
-        char localType = local[i];
-        char wireType = wire[i];
-
-        if (localType != wireType) {
-            // `bool` and `signed char` are interchangeable.
-            if (strchr("Bc", localType) && strchr("Bc", wireType))
-                continue;
-            return false;
-        }
-    }
-    return true;
-}
-
 static String replyBlockSignature(Protocol *protocol, SEL selector, NSUInteger blockIndex)
 {
     // Required, non-inherited method:
@@ -279,7 +256,7 @@
             return;
         }
 
-        if (!blockSignaturesAreCompatible(wireBlockSignature, expectedBlockSignature)) {
+        if (!WebKit::methodSignaturesAreCompatible(wireBlockSignature, expectedBlockSignature)) {
             NSLog(@"_invokeMethod: Failed to validate reply block signature: %s != %s", wireBlockSignature.utf8().data(), expectedBlockSignature.utf8().data());
             ASSERT_NOT_REACHED();
             return;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to