Fix Crash in Mail Search
authormegan_gardner@apple.com <megan_gardner@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Aug 2019 21:40:56 +0000 (21:40 +0000)
committermegan_gardner@apple.com <megan_gardner@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Aug 2019 21:40:56 +0000 (21:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=200589
Source/WebKit:

<rdar://problem/53666720>

Reviewed by Tim Horton.

If we search in Mail backwards first, for AppKit reasons
we get a -1 for the index of the found item.
Do not try and insert data in this case.

* UIProcess/mac/WKTextFinderClient.mm:

Tools:

Reviewed by Tim Horton.

If you search backwards first in mail, we would crash,
this tests that codepath.

* TestWebKitAPI/Tests/WebKitCocoa/FindInPage.mm:
(TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@248548 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/mac/WKTextFinderClient.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/FindInPage.mm

index 8fdcd5d..959459b 100644 (file)
@@ -1,3 +1,17 @@
+2019-08-12  Megan Gardner  <megan_gardner@apple.com>
+
+        Fix Crash in Mail Search
+        https://bugs.webkit.org/show_bug.cgi?id=200589
+        <rdar://problem/53666720>
+
+        Reviewed by Tim Horton.
+
+        If we search in Mail backwards first, for AppKit reasons 
+        we get a -1 for the index of the found item.
+        Do not try and insert data in this case.
+
+        * UIProcess/mac/WKTextFinderClient.mm:
+
 2019-08-12  Adrian Perez de Castro  <aperez@igalia.com>
 
         [WPE][GTK] Fix building without unified sources
index b7f6c2f..660317c 100644 (file)
@@ -81,7 +81,9 @@ private:
             // The rest will remain empty, but it's important to NSTextFinder
             // that they at least exist.
             allMatches.resize(matchCount);
-            allMatches[matchIndex].appendVector(matchRects);
+            // FIXME: Clean this up and figure out why we are getting a -1 index
+            if (matchIndex >= 0 && static_cast<uint32_t>(matchIndex) < matchCount)
+                allMatches[matchIndex].appendVector(matchRects);
         }
 
         [m_textFinderClient didFindStringMatchesWithRects:allMatches didWrapAround:didWrapAround];
index 9007737..2da3faf 100644 (file)
@@ -1,3 +1,16 @@
+2019-08-12  Megan Gardner  <megan_gardner@apple.com>
+
+        Fix Crash in Mail Search
+        https://bugs.webkit.org/show_bug.cgi?id=200589
+
+        Reviewed by Tim Horton.
+
+        If you search backwards first in mail, we would crash,
+        this tests that codepath.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/FindInPage.mm:
+        (TEST):
+
 2019-08-12  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [iPadOS] Web pages sometimes load at half width in Safari
index 41eb163..389ecdc 100644 (file)
@@ -224,6 +224,22 @@ TEST(WebKit, FindInPageWrappingDisabled)
     EXPECT_FALSE(result.didWrap);
 }
 
+TEST(WebKit, FindInPageBackwardsFirst)
+{
+    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]);
+    [webView _setOverrideDeviceScaleFactor:2];
+
+    [webView loadHTMLString:@"word word" baseURL:nil];
+    [webView _test_waitForDidFinishNavigation];
+
+    // Find one match, doing an incremental search.
+    auto result = findMatches(webView.get(), @"word", wrapBackwardsFindOptions, 1);
+    EXPECT_EQ((NSUInteger)1, [result.matches count]);
+
+    result = findMatches(webView.get(), @"word", wrapBackwardsFindOptions, 1);
+    EXPECT_EQ((NSUInteger)1, [result.matches count]);
+}
+
 TEST(WebKit, FindInPageWrappingSubframe)
 {
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]);