mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 13:49:16 +00:00
LibWeb: Use code unit offsets in Document::find_matching_text()
We were passing in byte offsets instead of UTF-16 code unit offsets, which could lead to crashes if the offsets found exceeded the number of code units in text fragments on the page. Fixes #4908. Co-authored-by: Tim Ledbetter <tim.ledbetter@ladybird.org>
This commit is contained in:
parent
cc0a28ee7d
commit
b42c2c5e8f
Notes:
github-actions[bot]
2025-06-13 13:10:45 +00:00
Author: https://github.com/gmta
Commit: b42c2c5e8f
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5067
Reviewed-by: https://github.com/tcl3
Reviewed-by: https://github.com/trflynn89
5 changed files with 24 additions and 15 deletions
|
@ -60,7 +60,7 @@ void Viewport::update_text_blocks()
|
|||
|
||||
if (layout_node.is_box() || layout_node.is_generated()) {
|
||||
if (!builder.is_empty()) {
|
||||
text_blocks.append({ builder.to_string_without_validation(), text_positions });
|
||||
text_blocks.append({ MUST(AK::utf8_to_utf16(builder.string_view())), text_positions });
|
||||
current_start_position = 0;
|
||||
text_positions.clear_with_capacity();
|
||||
builder.clear();
|
||||
|
@ -80,7 +80,8 @@ void Viewport::update_text_blocks()
|
|||
}
|
||||
|
||||
auto const& current_node_text = text_node->text_for_rendering();
|
||||
current_start_position += current_node_text.bytes_as_string_view().length();
|
||||
auto const current_node_text_utf16 = MUST(AK::utf8_to_utf16(current_node_text));
|
||||
current_start_position += current_node_text_utf16.data.size();
|
||||
builder.append(move(current_node_text));
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +90,7 @@ void Viewport::update_text_blocks()
|
|||
});
|
||||
|
||||
if (!builder.is_empty())
|
||||
text_blocks.append({ builder.to_string_without_validation(), text_positions });
|
||||
text_blocks.append({ MUST(AK::utf8_to_utf16(builder.string_view())), text_positions });
|
||||
|
||||
m_text_blocks = move(text_blocks);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue