Title: [290377] trunk
Revision
290377
Author
[email protected]
Date
2022-02-23 09:50:53 -0800 (Wed, 23 Feb 2022)

Log Message

Fix for assert crash in AccessibilityRenderObject::visiblePositionForIndex.
https://bugs.webkit.org/show_bug.cgi?id=236795
rdar://89025180

Reviewed by Chris Fleizach.

Source/WebCore:

Test: accessibility/native-text-control-attributed-string.html

In some cases like the one described in the bug, AccessibilityRenderObject::visiblePositionForIndex
is passed an index greater than the length of the text actually contained
in the text control. This triggers this assert that verifies that you can
round-trip from index to VisiblePosition and back to index. This patch
does a bounds check in the index and adjust if necessary.
The test exercise this method through the JS AccessibilityUIElement::attributedStringForRange
for both <input> of type text and password.

* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::visiblePositionForIndex const):

LayoutTests:

* accessibility/native-text-control-attributed-string-expected.txt: Added.
* accessibility/native-text-control-attributed-string.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (290376 => 290377)


--- trunk/LayoutTests/ChangeLog	2022-02-23 16:35:55 UTC (rev 290376)
+++ trunk/LayoutTests/ChangeLog	2022-02-23 17:50:53 UTC (rev 290377)
@@ -1,3 +1,14 @@
+2022-02-23  Andres Gonzalez  <[email protected]>
+
+        Fix for assert crash in AccessibilityRenderObject::visiblePositionForIndex.
+        https://bugs.webkit.org/show_bug.cgi?id=236795
+        rdar://89025180
+
+        Reviewed by Chris Fleizach.
+
+        * accessibility/native-text-control-attributed-string-expected.txt: Added.
+        * accessibility/native-text-control-attributed-string.html: Added.
+
 2022-02-23  Alejandro G. Castro  <[email protected]>
 
         Unreviewed test gardening.

Added: trunk/LayoutTests/accessibility/native-text-control-attributed-string-expected.txt (0 => 290377)


--- trunk/LayoutTests/accessibility/native-text-control-attributed-string-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/accessibility/native-text-control-attributed-string-expected.txt	2022-02-23 17:50:53 UTC (rev 290377)
@@ -0,0 +1,95 @@
+Tests that attributedStringForRange works properly for native text and password fields, including for ranges out of bound.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Attributed string for range (0, 9): some word{
+    AXBackgroundColor = " [ (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1)] ( 0 0 0 0 )";
+    AXFont =     {
+        AXFontFamily = ".AppleSystemUIFont";
+        AXFontName = ".SFNS-Regular";
+        AXFontSize = 11;
+        AXVisibleName = "System Font Regular";
+    };
+    AXForegroundColor = " [ (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1)] ( 0 0 0 1 )";
+}
+Attributed string for range (0, 3): som{
+    AXBackgroundColor = " [ (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1)] ( 0 0 0 0 )";
+    AXFont =     {
+        AXFontFamily = ".AppleSystemUIFont";
+        AXFontName = ".SFNS-Regular";
+        AXFontSize = 11;
+        AXVisibleName = "System Font Regular";
+    };
+    AXForegroundColor = " [ (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1)] ( 0 0 0 1 )";
+}
+Attributed string for range (5, 4): word{
+    AXBackgroundColor = " [ (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1)] ( 0 0 0 0 )";
+    AXFont =     {
+        AXFontFamily = ".AppleSystemUIFont";
+        AXFontName = ".SFNS-Regular";
+        AXFontSize = 11;
+        AXVisibleName = "System Font Regular";
+    };
+    AXForegroundColor = " [ (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1)] ( 0 0 0 1 )";
+}
+Attributed string for range (5, 10): null
+Attributed string for range (10, 1): null
+Attributed string for range (-1, 1): s{
+    AXBackgroundColor = " [ (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1)] ( 0 0 0 0 )";
+    AXFont =     {
+        AXFontFamily = ".AppleSystemUIFont";
+        AXFontName = ".SFNS-Regular";
+        AXFontSize = 11;
+        AXVisibleName = "System Font Regular";
+    };
+    AXForegroundColor = " [ (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1)] ( 0 0 0 1 )";
+}
+
+Attributed string for range (0, 3): •••{
+    AXBackgroundColor = " [ (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1)] ( 0 0 0 0 )";
+    AXFont =     {
+        AXFontFamily = ".AppleSystemUIFont";
+        AXFontName = ".SFNS-Regular";
+        AXFontSize = 11;
+        AXVisibleName = "System Font Regular";
+    };
+    AXForegroundColor = " [ (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1)] ( 0 0 0 1 )";
+}
+Attributed string for range (0, 2): ••{
+    AXBackgroundColor = " [ (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1)] ( 0 0 0 0 )";
+    AXFont =     {
+        AXFontFamily = ".AppleSystemUIFont";
+        AXFontName = ".SFNS-Regular";
+        AXFontSize = 11;
+        AXVisibleName = "System Font Regular";
+    };
+    AXForegroundColor = " [ (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1)] ( 0 0 0 1 )";
+}
+Attributed string for range (1, 2): ••{
+    AXBackgroundColor = " [ (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1)] ( 0 0 0 0 )";
+    AXFont =     {
+        AXFontFamily = ".AppleSystemUIFont";
+        AXFontName = ".SFNS-Regular";
+        AXFontSize = 11;
+        AXVisibleName = "System Font Regular";
+    };
+    AXForegroundColor = " [ (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1)] ( 0 0 0 1 )";
+}
+Attributed string for range (1, 10): null
+Attributed string for range (10, 1): null
+Attributed string for range (-1, 1): •{
+    AXBackgroundColor = " [ (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1)] ( 0 0 0 0 )";
+    AXFont =     {
+        AXFontFamily = ".AppleSystemUIFont";
+        AXFontName = ".SFNS-Regular";
+        AXFontSize = 11;
+        AXVisibleName = "System Font Regular";
+    };
+    AXForegroundColor = " [ (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1)] ( 0 0 0 1 )";
+}
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/accessibility/native-text-control-attributed-string.html (0 => 290377)


--- trunk/LayoutTests/accessibility/native-text-control-attributed-string.html	                        (rev 0)
+++ trunk/LayoutTests/accessibility/native-text-control-attributed-string.html	2022-02-23 17:50:53 UTC (rev 290377)
@@ -0,0 +1,44 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+
+<input type="text" id="textfield" value="some word"></input>
+<input type="password" id="passwordfield" value="pwd"></input>
+
+<script>
+    description("Tests that attributedStringForRange works properly for native text and password fields, including for ranges out of bound.");
+
+    if (window.accessibilityController) {
+        let output = "";
+        let textField = accessibilityController.accessibleElementById("textfield");
+        // Entire text.
+        output = `Attributed string for range (0, 9): ${textField.attributedStringForRange(0, 9)}\n`;
+        // Text at the start.
+        output += `Attributed string for range (0, 3): ${textField.attributedStringForRange(0, 3)}\n`;
+        // Text at the end.
+        output += `Attributed string for range (5, 4): ${textField.attributedStringForRange(5, 4)}\n`;
+        // Range out of bounds.
+        output += `Attributed string for range (5, 10): ${textField.attributedStringForRange(5, 10)}\n`;
+        output += `Attributed string for range (10, 1): ${textField.attributedStringForRange(10, 1)}\n`;
+        output += `Attributed string for range (-1, 1): ${textField.attributedStringForRange(-1, 1)}\n`;
+        debug(output);
+
+        let passwordField = accessibilityController.accessibleElementById("passwordfield");
+        // Entire text.
+        output = `Attributed string for range (0, 3): ${passwordField.attributedStringForRange(0, 3)}\n`;
+        // Text at the start.
+        output += `Attributed string for range (0, 2): ${passwordField.attributedStringForRange(0, 2)}\n`;
+        // Text at the end.
+        output += `Attributed string for range (1, 2): ${passwordField.attributedStringForRange(1, 2)}\n`;
+        // Range out of bounds.
+        output += `Attributed string for range (1, 10): ${passwordField.attributedStringForRange(1, 10)}\n`;
+        output += `Attributed string for range (10, 1): ${passwordField.attributedStringForRange(10, 1)}\n`;
+        output += `Attributed string for range (-1, 1): ${passwordField.attributedStringForRange(-1, 1)}\n`;
+        debug(output);
+    }
+</script>
+</body>
+</html>

Modified: trunk/LayoutTests/platform/gtk/TestExpectations (290376 => 290377)


--- trunk/LayoutTests/platform/gtk/TestExpectations	2022-02-23 16:35:55 UTC (rev 290376)
+++ trunk/LayoutTests/platform/gtk/TestExpectations	2022-02-23 17:50:53 UTC (rev 290377)
@@ -1864,6 +1864,7 @@
 #////////////////////////////////////////////////////////////////////////////////////////
 
 accessibility/dialog-properties.html [ Skip ]
+accessibility/native-text-control-attributed-string.html [ Skip ]
 
 # These tests require platform support.
 media/media-allowed-codecs.html

Modified: trunk/LayoutTests/platform/mac-wk1/TestExpectations (290376 => 290377)


--- trunk/LayoutTests/platform/mac-wk1/TestExpectations	2022-02-23 16:35:55 UTC (rev 290376)
+++ trunk/LayoutTests/platform/mac-wk1/TestExpectations	2022-02-23 17:50:53 UTC (rev 290377)
@@ -1612,6 +1612,7 @@
 
 # rdar://80331434 ([ Mac WK1 Release ] accessibility/loading-iframe-sends-notification.html is a flaky timeout)
 [ Release ] accessibility/loading-iframe-sends-notification.html [ Pass Timeout ]
+accessibility/native-text-control-attributed-string.html [ Skip ]
 
 webkit.org/b/227516 fast/shadow-dom/style-resolver-sharing.html [ Pass Failure ]
 

Modified: trunk/LayoutTests/platform/win/TestExpectations (290376 => 290377)


--- trunk/LayoutTests/platform/win/TestExpectations	2022-02-23 16:35:55 UTC (rev 290376)
+++ trunk/LayoutTests/platform/win/TestExpectations	2022-02-23 17:50:53 UTC (rev 290377)
@@ -4919,6 +4919,7 @@
 accessibility/selected-state-changed-notifications.html [ Skip ]
 accessibility/element-line-rects-and-text.html [ Skip ]
 accessibility/dialog-properties.html [ Skip ]
+accessibility/native-text-control-attributed-string.html [ Skip ]
 
 webkit.org/b/229247 http/tests/fetch/keepalive-fetch-2.html [ Pass Failure ]
 

Modified: trunk/Source/WebCore/ChangeLog (290376 => 290377)


--- trunk/Source/WebCore/ChangeLog	2022-02-23 16:35:55 UTC (rev 290376)
+++ trunk/Source/WebCore/ChangeLog	2022-02-23 17:50:53 UTC (rev 290377)
@@ -1,3 +1,24 @@
+2022-02-23  Andres Gonzalez  <[email protected]>
+
+        Fix for assert crash in AccessibilityRenderObject::visiblePositionForIndex.
+        https://bugs.webkit.org/show_bug.cgi?id=236795
+        rdar://89025180
+
+        Reviewed by Chris Fleizach.
+
+        Test: accessibility/native-text-control-attributed-string.html
+
+        In some cases like the one described in the bug, AccessibilityRenderObject::visiblePositionForIndex
+        is passed an index greater than the length of the text actually contained
+        in the text control. This triggers this assert that verifies that you can
+        round-trip from index to VisiblePosition and back to index. This patch
+        does a bounds check in the index and adjust if necessary.
+        The test exercise this method through the JS AccessibilityUIElement::attributedStringForRange
+        for both <input> of type text and password.
+
+        * accessibility/AccessibilityRenderObject.cpp:
+        (WebCore::AccessibilityRenderObject::visiblePositionForIndex const):
+
 2022-02-23  Diego Pino Garcia  <[email protected]>
 
         [GTK] Unreviewed, build fix for Debian Stable after r290366

Modified: trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp (290376 => 290377)


--- trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp	2022-02-23 16:35:55 UTC (rev 290376)
+++ trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp	2022-02-23 17:50:53 UTC (rev 290377)
@@ -112,6 +112,7 @@
 #include "TextControlInnerElements.h"
 #include "TextIterator.h"
 #include "VisibleUnits.h"
+#include <algorithm>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/StdLibExtras.h>
 #include <wtf/unicode/CharacterNames.h>
@@ -2097,21 +2098,23 @@
     selection.modify(FrameSelection::AlterationExtend, SelectionDirection::Right, TextGranularity::LineBoundary);
     return selection.selection();
 }
-    
+
 VisiblePosition AccessibilityRenderObject::visiblePositionForIndex(int index) const
 {
     if (!m_renderer)
-        return VisiblePosition();
+        return { };
 
-    if (isNativeTextControl())
-        return downcast<RenderTextControl>(*m_renderer).textFormControlElement().visiblePositionForIndex(index);
+    if (isNativeTextControl()) {
+        auto& textControl = downcast<RenderTextControl>(*m_renderer).textFormControlElement();
+        return textControl.visiblePositionForIndex(std::clamp(index, 0, static_cast<int>(textControl.value().length())));
+    }
 
     if (!allowsTextRanges() && !is<RenderText>(*m_renderer))
-        return VisiblePosition();
-    
+        return { };
+
     Node* node = m_renderer->node();
     if (!node)
-        return VisiblePosition();
+        return { };
 
 #if USE(ATSPI)
     // We need to consider replaced elements for GTK, as they will be presented with the 'object replacement character' (0xFFFC).
@@ -2120,7 +2123,7 @@
     return visiblePositionForIndexUsingCharacterIterator(*node, index);
 #endif
 }
-    
+
 int AccessibilityRenderObject::indexForVisiblePosition(const VisiblePosition& position) const
 {
     if (!m_renderer)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to