From 64a2844ce80a47f93f98b082600d27087ba2f606 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Fri, 12 Mar 2021 22:35:02 -0800 Subject: [PATCH] Fix attribute replace bug in TextAXNodeWrapper (flutter/engine#24986) When replacing an int/float/bool attribute on the test node, we want to erase the range from the iterator returned by remove_if to end(), which may be an empty range. In the case where remove_if() returns end(), the single-parameter variant of erase() attempts to remove an element past the end of the container. --- .../ax/platform/test_ax_node_wrapper.cc | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/engine/src/flutter/third_party/accessibility/ax/platform/test_ax_node_wrapper.cc b/engine/src/flutter/third_party/accessibility/ax/platform/test_ax_node_wrapper.cc index 04513c6d72..6ed39a7bbc 100644 --- a/engine/src/flutter/third_party/accessibility/ax/platform/test_ax_node_wrapper.cc +++ b/engine/src/flutter/third_party/accessibility/ax/platform/test_ax_node_wrapper.cc @@ -369,9 +369,10 @@ void TestAXNodeWrapper::ReplaceIntAttribute(int32_t node_id, std::vector>& attributes = new_data.int_attributes; - attributes.erase(std::remove_if( + auto it = std::remove_if( attributes.begin(), attributes.end(), - [attribute](auto& pair) { return pair.first == attribute; })); + [attribute](auto& pair) { return pair.first == attribute; }); + attributes.erase(it, attributes.end()); new_data.AddIntAttribute(attribute, value); node->SetData(new_data); @@ -384,9 +385,10 @@ void TestAXNodeWrapper::ReplaceFloatAttribute( std::vector>& attributes = new_data.float_attributes; - attributes.erase(std::remove_if( + auto it = std::remove_if( attributes.begin(), attributes.end(), - [attribute](auto& pair) { return pair.first == attribute; })); + [attribute](auto& pair) { return pair.first == attribute; }); + attributes.erase(it, attributes.end()); new_data.AddFloatAttribute(attribute, value); node_->SetData(new_data); @@ -398,9 +400,10 @@ void TestAXNodeWrapper::ReplaceBoolAttribute(ax::mojom::BoolAttribute attribute, std::vector>& attributes = new_data.bool_attributes; - attributes.erase(std::remove_if( + auto it = std::remove_if( attributes.begin(), attributes.end(), - [attribute](auto& pair) { return pair.first == attribute; })); + [attribute](auto& pair) { return pair.first == attribute; }); + attributes.erase(it, attributes.end()); new_data.AddBoolAttribute(attribute, value); node_->SetData(new_data); @@ -413,9 +416,10 @@ void TestAXNodeWrapper::ReplaceStringAttribute( std::vector>& attributes = new_data.string_attributes; - attributes.erase(std::remove_if( + auto it = std::remove_if( attributes.begin(), attributes.end(), - [attribute](auto& pair) { return pair.first == attribute; })); + [attribute](auto& pair) { return pair.first == attribute; }); + attributes.erase(it, attributes.end()); new_data.AddStringAttribute(attribute, value); node_->SetData(new_data);