Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Check for index bounds in RTL handling for trailing whitespace runs. #12336

Merged
merged 9 commits into from
Sep 23, 2019

Conversation

GaryQian
Copy link
Contributor

This prevents crashing when leading whitespace occurs in RTL text. This is a semi-temporary fix to prevent rolling back the change that fixes RTL text input in general.

Fixes flutter/flutter#39553

@@ -415,7 +415,11 @@ bool ParagraphTxt::ComputeBidiRuns(std::vector<BidiRun>* result) {
//
// This only applies to the final whitespace at the end as other whitespace is
// no longer ambiguous when surrounded by additional text.

// TODO(garyq): Handle this in the text editor caret code instead at layout
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd still prefer to revert this instead of adding more complex post-processing to the output of the bidi algorithm.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is viable for the RTL users of flutter if we revert this without a complete solution ready to go, as it causes all RTL input to look completely wrong. Reverting would make RTL essentially unusable until the final solution is rolled.

@@ -429,6 +433,9 @@ bool ParagraphTxt::ComputeBidiRuns(std::vector<BidiRun>* result) {
if (u_hasBinaryProperty(last_char, UCHAR_WHITE_SPACE)) {
has_trailing_whitespace = true;
bidi_run_count--;
if (bidi_run_start == 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, the goal here is merging the last visual run into the second-to-last run if the last run consists of a single whitespace character.

Would it work to check whether the last run's start index follows the second-to-last run's end index here? If that is the case, then it's safe to reduce the bidi_run_count and increase the final run's length.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that should be a more robust check. Implemented.

ubidi_getVisualRun(bidi.get(), bidi_run_count - 2,
&second_last_bidi_run_start,
&second_last_bidi_run_length);
if (bidi_run_start <= second_last_bidi_run_start) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two cases:

  1. last_bidi_run_start == second_last_bidi_run_end + 1
  2. last_bidi_run_start == second_last_bidi_run_start - 1

For #1, it's safe to merge the last run into the second-to-last run.

For #2, the is_leading flag will merge the last two runs to create a run where the last whitespace occurs at the start of the final run. Is that desirable? Or would we be better off leaving the bidi runs unmodified in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me try both modifying and not to see which one we want in terms of text input.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it looks like both produce reasonable results during text input. In this case, I will prefer not modifying it when it is leading.

@GaryQian
Copy link
Contributor Author

@jason-simmons Ready for additional review!

ubidi_getVisualRun(bidi.get(), bidi_run_count - 2,
&second_last_bidi_run_start,
&second_last_bidi_run_length);
if (bidi_run_start >= second_last_bidi_run_start) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check whether bidi_run_start == second_last_bidi_run_start + second_last_bidi_run_length

has_trailing_whitespace will extend the second-to-last run by one character. This only makes sense if the additional character is the whitespace character comprising the final run

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, forgot to push -f, thought I had pushed the changes already!

@GaryQian GaryQian force-pushed the rtlleadingspacecrash branch from 4ea01db to 443a61d Compare September 23, 2019 19:36
@GaryQian GaryQian merged commit 21b456d into flutter:master Sep 23, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 24, 2019
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request Sep 24, 2019
[email protected]:flutter/engine.git/compare/e7fd442410f4...953ac71

git log e7fd442..953ac71 --no-merges --oneline
2019-09-24 [email protected] Roll src/third_party/dart acac9ab11b..d53d355c6c (12 commits)
2019-09-24 [email protected] Roll src/third_party/skia b4b1005d485f..c096654fa7c6 (1 commits) (flutter/engine#12415)
2019-09-24 [email protected] Roll src/third_party/skia b3542d95da65..b4b1005d485f (6 commits) (flutter/engine#12414)
2019-09-24 [email protected] Write MINIMAL_SDK to exception message (flutter/engine#11345)
2019-09-23 [email protected] Track "mouse leave" event (flutter/engine#12363)
2019-09-23 [email protected] Roll src/third_party/dart 77ff89b223..acac9ab11b (6 commits)
2019-09-23 [email protected] Don't send pointer events when the framework isn't ready yet (flutter/engine#12403)
2019-09-23 [email protected] Update test to verify that secondary isolate gets shutdown before root isolate exits. (flutter/engine#12342)
2019-09-23 [email protected] Roll src/third_party/skia 57ef68077574..b3542d95da65 (12 commits) (flutter/engine#12409)
2019-09-23 [email protected] Update --dart-vm-flags whitelist to include --write-service-info and --sample-buffer-duration (flutter/engine#12395)
2019-09-23 [email protected] Add system font change listener for windows (flutter/engine#12276)
2019-09-23 [email protected] Roll fuchsia/sdk/core/mac-amd64 from xPX7p... to kgFwg... (flutter/engine#12405)
2019-09-23 [email protected] Check for index bounds in RTL handling for trailing whitespace runs. (flutter/engine#12336)
2019-09-23 [email protected] Roll fuchsia/sdk/core/linux-amd64 from F-g18... to NY2A5... (flutter/engine#12407)
2019-09-23 [email protected] Roll src/third_party/dart f546362691..77ff89b223 (6 commits)
2019-09-23 [email protected] Updating text field location in IOS as a pre-work for spellcheck (flutter/engine#12192)
2019-09-23 [email protected] Roll buildroot and remove toolchain prefix. (flutter/engine#12324)
2019-09-23 [email protected] Roll src/third_party/dart 94dd49cdb6..f546362691 (1 commits)


If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC [email protected] on the revert to ensure that a human
is aware of the problem.

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md
Inconnu08 pushed a commit to Inconnu08/flutter that referenced this pull request Sep 30, 2019
[email protected]:flutter/engine.git/compare/e7fd442410f4...953ac71

git log e7fd442..953ac71 --no-merges --oneline
2019-09-24 [email protected] Roll src/third_party/dart acac9ab11b..d53d355c6c (12 commits)
2019-09-24 [email protected] Roll src/third_party/skia b4b1005d485f..c096654fa7c6 (1 commits) (flutter/engine#12415)
2019-09-24 [email protected] Roll src/third_party/skia b3542d95da65..b4b1005d485f (6 commits) (flutter/engine#12414)
2019-09-24 [email protected] Write MINIMAL_SDK to exception message (flutter/engine#11345)
2019-09-23 [email protected] Track "mouse leave" event (flutter/engine#12363)
2019-09-23 [email protected] Roll src/third_party/dart 77ff89b223..acac9ab11b (6 commits)
2019-09-23 [email protected] Don't send pointer events when the framework isn't ready yet (flutter/engine#12403)
2019-09-23 [email protected] Update test to verify that secondary isolate gets shutdown before root isolate exits. (flutter/engine#12342)
2019-09-23 [email protected] Roll src/third_party/skia 57ef68077574..b3542d95da65 (12 commits) (flutter/engine#12409)
2019-09-23 [email protected] Update --dart-vm-flags whitelist to include --write-service-info and --sample-buffer-duration (flutter/engine#12395)
2019-09-23 [email protected] Add system font change listener for windows (flutter/engine#12276)
2019-09-23 [email protected] Roll fuchsia/sdk/core/mac-amd64 from xPX7p... to kgFwg... (flutter/engine#12405)
2019-09-23 [email protected] Check for index bounds in RTL handling for trailing whitespace runs. (flutter/engine#12336)
2019-09-23 [email protected] Roll fuchsia/sdk/core/linux-amd64 from F-g18... to NY2A5... (flutter/engine#12407)
2019-09-23 [email protected] Roll src/third_party/dart f546362691..77ff89b223 (6 commits)
2019-09-23 [email protected] Updating text field location in IOS as a pre-work for spellcheck (flutter/engine#12192)
2019-09-23 [email protected] Roll buildroot and remove toolchain prefix. (flutter/engine#12324)
2019-09-23 [email protected] Roll src/third_party/dart 94dd49cdb6..f546362691 (1 commits)


If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC [email protected] on the revert to ensure that a human
is aware of the problem.

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Leading space in RTL text crashes app
3 participants