Commit ba45676b authored by Joanmarie Diggs's avatar Joanmarie Diggs Committed by Commit Bot

Fix crash in AXPlatformNodeAuraLinux::GetTextAttributes

The crash is due to the TextAttributeList never getting set in the
TextAttributeMap for the node when the node is an empty Role::kButton
from Blink.

BrowserAccessibility::IsLeaf was enforcing leafiness for Role::kButton
when there is exactly one child and that child is text. In all other
cases (including no children), IsLeaf was returning false for buttons.
As a result, BrowserAccessibility::ComputeTextAttributeMap was looking
to the non-existent children of empty buttons rather than using the
default attributes as it does for all other leaf nodes.

To fix the crash, and potentially other issues, check for childless
buttons in BrowserAccessibility::IsLeaf.

AX-Relnotes: Prevents browser crash which can result from an assistive
technology asking for the text attributes for an empty button.

Bug: 1107407
Change-Id: I985ba0dc5c6eb1b28bcfe9e6c1e18f44ba0fcfe1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2310332Reviewed-by: default avatarNektarios Paisios <nektar@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: Nektarios Paisios <nektar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792310}
parent 19a045cc
......@@ -1549,7 +1549,9 @@ bool BrowserAccessibility::IsLeaf() const {
// children. The only exception to enforce leafiness is when the button has
// a single text child and to prevent screen readers from double speak.
if (GetRole() == ax::mojom::Role::kButton) {
return InternalChildCount() == 1 && InternalGetFirstChild()->IsText();
uint32_t child_count = InternalChildCount();
return !child_count ||
(child_count == 1 && InternalGetFirstChild()->IsText());
}
return node()->IsLeaf();
}
......@@ -2266,6 +2268,8 @@ ui::TextAttributeMap BrowserAccessibility::ComputeTextAttributeMap(
return attributes_map;
}
DCHECK(PlatformChildCount());
int start_offset = 0;
for (BrowserAccessibility::PlatformChildIterator it = PlatformChildrenBegin();
it != PlatformChildrenEnd(); ++it) {
......
......@@ -305,6 +305,59 @@ TEST_F(BrowserAccessibilityAuraLinuxTest, TestComplexHypertext) {
manager.reset();
}
TEST_F(BrowserAccessibilityAuraLinuxTest, TestTextAttributesInButtons) {
ui::AXNodeData root;
root.id = 1;
root.role = ax::mojom::Role::kRootWebArea;
root.AddState(ax::mojom::State::kFocusable);
ui::AXNodeData button;
button.id = 2;
button.role = ax::mojom::Role::kButton;
button.AddStringAttribute(ax::mojom::StringAttribute::kFontFamily, "Times");
root.child_ids.push_back(button.id);
ui::AXNodeData text;
text.id = 3;
text.role = ax::mojom::Role::kStaticText;
text.SetName("OK");
button.child_ids.push_back(text.id);
ui::AXNodeData empty_button;
empty_button.id = 4;
empty_button.role = ax::mojom::Role::kButton;
empty_button.AddStringAttribute(ax::mojom::StringAttribute::kFontFamily,
"Times");
root.child_ids.push_back(empty_button.id);
ui::AXTreeUpdate update = MakeAXTreeUpdate(root, button, text, empty_button);
std::unique_ptr<BrowserAccessibilityManager> manager(
BrowserAccessibilityManager::Create(
update, test_browser_accessibility_delegate_.get()));
BrowserAccessibilityAuraLinux* ax_root =
ToBrowserAccessibilityAuraLinux(manager->GetRoot());
BrowserAccessibilityAuraLinux* ax_button =
ToBrowserAccessibilityAuraLinux(ax_root->PlatformGetChild(0));
AtkObject* atk_button = ax_button->GetNode()->GetNativeViewAccessible();
int start_offset, end_offset;
AtkAttributeSet* attributes = atk_text_get_run_attributes(
ATK_TEXT(atk_button), 0, &start_offset, &end_offset);
ASSERT_EQ(1U, g_slist_length(attributes));
atk_attribute_set_free(attributes);
BrowserAccessibilityAuraLinux* ax_empty_button =
ToBrowserAccessibilityAuraLinux(ax_root->PlatformGetChild(1));
AtkObject* atk_empty_button =
ax_empty_button->GetNode()->GetNativeViewAccessible();
attributes = atk_text_get_run_attributes(ATK_TEXT(atk_empty_button), 0,
&start_offset, &end_offset);
ASSERT_EQ(1U, g_slist_length(attributes));
atk_attribute_set_free(attributes);
}
TEST_F(BrowserAccessibilityAuraLinuxTest,
TestTextAttributesInContentEditables) {
auto has_attribute = [](AtkAttributeSet* attributes,
......
......@@ -4853,6 +4853,10 @@ const TextAttributeList& AXPlatformNodeAuraLinux::GetTextAttributes(
UTF16ToUnicodeOffsetInText(style_start));
SetIntPointerValueIfNotNull(end_offset,
UTF16ToUnicodeOffsetInText(style_end));
if (iterator == offset_to_text_attributes_.end())
return default_text_attributes_;
return iterator->second;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment