Title: [115985] trunk/Source/WebCore
Revision
115985
Author
[email protected]
Date
2012-05-03 10:07:00 -0700 (Thu, 03 May 2012)

Log Message

accessibility/misspelled-attributed-string.html test sometimes throws exceptions
https://bugs.webkit.org/show_bug.cgi?id=85081

Reviewed by Darin Adler.

Add in more range checking in case we get back ranges from spell checking that are wrong.

* accessibility/mac/WebAccessibilityObjectWrapper.mm:
(AXAttributeStringSetFont):
(AXAttributeStringSetColor):
(AXAttributeStringSetNumber):
(AXAttributeStringSetBlockquoteLevel):
(AXAttributeStringSetHeadingLevel):
(AXAttributeStringSetElement):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (115984 => 115985)


--- trunk/Source/WebCore/ChangeLog	2012-05-03 16:48:42 UTC (rev 115984)
+++ trunk/Source/WebCore/ChangeLog	2012-05-03 17:07:00 UTC (rev 115985)
@@ -1,3 +1,20 @@
+2012-05-03  Chris Fleizach  <[email protected]>
+
+        accessibility/misspelled-attributed-string.html test sometimes throws exceptions
+        https://bugs.webkit.org/show_bug.cgi?id=85081
+
+        Reviewed by Darin Adler.
+
+        Add in more range checking in case we get back ranges from spell checking that are wrong.
+
+        * accessibility/mac/WebAccessibilityObjectWrapper.mm:
+        (AXAttributeStringSetFont):
+        (AXAttributeStringSetColor):
+        (AXAttributeStringSetNumber):
+        (AXAttributeStringSetBlockquoteLevel):
+        (AXAttributeStringSetHeadingLevel):
+        (AXAttributeStringSetElement):
+
 2012-05-03  Pavel Feldman  <[email protected]>
 
         Web Inspector: move canonical mime type calculation to Resource

Modified: trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapper.mm (115984 => 115985)


--- trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapper.mm	2012-05-03 16:48:42 UTC (rev 115984)
+++ trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapper.mm	2012-05-03 17:07:00 UTC (rev 115985)
@@ -569,12 +569,20 @@
     return AXTextMarkerRange(textMarker1, textMarker2);
 }
 
+// When modifying attributed strings, the range can come from a source which may provide faulty information (e.g. the spell checker).
+// To protect against such cases the range should be validated before adding or removing attributes.
+static BOOL AXAttributedStringRangeIsValid(NSAttributedString* attrString, NSRange range)
+{
+    return (range.location < [attrString length] && NSMaxRange(range) <= [attrString length]);
+}
+
 static void AXAttributeStringSetFont(NSMutableAttributedString* attrString, NSString* attribute, NSFont* font, NSRange range)
 {
-    NSDictionary* dict;
+    if (!AXAttributedStringRangeIsValid(attrString, range))
+        return;
     
     if (font) {
-        dict = [NSDictionary dictionaryWithObjectsAndKeys:
+        NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:
             [font fontName]                             , NSAccessibilityFontNameKey,
             [font familyName]                           , NSAccessibilityFontFamilyKey,
             [font displayName]                          , NSAccessibilityVisibleNameKey,
@@ -612,6 +620,9 @@
 
 static void AXAttributeStringSetColor(NSMutableAttributedString* attrString, NSString* attribute, NSColor* color, NSRange range)
 {
+    if (!AXAttributedStringRangeIsValid(attrString, range))
+        return;
+
     if (color) {
         CGColorRef existingColor = (CGColorRef) [attrString attribute:attribute atIndex:range.location effectiveRange:nil];
         CGColorRef cgColor = CreateCGColorIfDifferent(color, existingColor);
@@ -625,6 +636,9 @@
 
 static void AXAttributeStringSetNumber(NSMutableAttributedString* attrString, NSString* attribute, NSNumber* number, NSRange range)
 {
+    if (!AXAttributedStringRangeIsValid(attrString, range))
+        return;
+
     if (number)
         [attrString addAttribute:attribute value:number range:range];
     else
@@ -695,6 +709,9 @@
 
 static void AXAttributeStringSetBlockquoteLevel(NSMutableAttributedString* attrString, RenderObject* renderer, NSRange range)
 {
+    if (!AXAttributedStringRangeIsValid(attrString, range))
+        return;
+
     AccessibilityObject* obj = renderer->document()->axObjectCache()->getOrCreate(renderer);
     int quoteLevel = obj->blockquoteLevel();
     
@@ -746,6 +763,9 @@
     if (!renderer)
         return;
     
+    if (!AXAttributedStringRangeIsValid(attrString, range))
+        return;
+    
     // Sometimes there are objects between the text and the heading. 
     // In those cases the parent hierarchy should be queried to see if there is a heading level.
     int parentHeadingLevel = 0;
@@ -764,6 +784,9 @@
 
 static void AXAttributeStringSetElement(NSMutableAttributedString* attrString, NSString* attribute, AccessibilityObject* object, NSRange range)
 {
+    if (!AXAttributedStringRangeIsValid(attrString, range))
+        return;
+
     if (object && object->isAccessibilityRenderObject()) {
         // make a serializable AX object
         
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to