Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiline TextInput crash when inserting/removing lots of text #489

Merged
merged 1 commit into from
Jul 8, 2020

Conversation

tido64
Copy link
Member

@tido64 tido64 commented Jul 8, 2020

  • I am removing an existing difference between facebook/react-native and microsoft/react-native-macos 👍
  • I am cherry-picking a change from Facebook's react-native into microsoft/react-native-macos 👍
  • I am making a fix / change for the macOS implementation of react-native
  • I am making a change required for Microsoft usage of react-native

Summary

It seems that the returned string that we use to set previousText can be mutated while it is waiting to be processed by RCTBridge .

Resolves #486

Changelog

[macOS] [Fixed] - Fix multiline TextInput crash when inserting/removing lots of text

Test Plan

Here's a screenshot showing that the length of previousText (0x600000d952c0) was 29483 when first accessed, but is 0 when the exception is thrown.

image

Microsoft Reviewers: Open in CodeFlow

@tido64 tido64 requested a review from tom-un as a code owner July 8, 2020 09:25
Copy link
Collaborator

@tom-un tom-un left a comment

Choose a reason for hiding this comment

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

See comment

It seems that the returned string that we use to set `previousText` can
be mutated while it is waiting to be processed by RCTBridge.
@tom-un tom-un merged commit c04ca1b into microsoft:master Jul 8, 2020
@tido64 tido64 deleted the fix-textinput-multiline-crash branch July 8, 2020 20:24
facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Jul 17, 2020
…29307)

Summary:
Multiline `TextInput` can crash when really long texts are inserted and removed quickly. This is caused by the fact that [`-[NSAttributedString string]`](https://developer.apple.com/documentation/foundation/nsattributedstring/1412616-string?language=objc) doesn't really return a copy, and may mutate the string while it is being used by `convertIdToFollyDynamic`. See microsoft#489 (comment) for more details on the issue.

This issue was originally reported in microsoft#486 and was fixed in microsoft#489.

## Changelog

[iOS] [Fixed] - Fix multiline TextInput crash when inserting/removing lots of text

Pull Request resolved: #29307

Test Plan:
1. Open RNTester > TextInput
2. Search for a multiline example
3. Copy some large text and paste it into the text input view
4. Remove some (or all) text
5. Repeat steps 3-4

Reviewed By: shergin

Differential Revision: D22488854

Pulled By: JoshuaGross

fbshipit-source-id: 6fab7818d68538450d93460361ff5934caf86c10
christophpurrer pushed a commit to christophpurrer/react-native-macos that referenced this pull request Jan 23, 2022
Summary:
The crash in T90602856 is very similar to one fixed by D22488854 (see discussion [in PR](microsoft#489 (comment))), and it's possible this `replacement` string also suffers from sharing the same backing store as the attributed string (maybe only when the range encompasses the entire string?) and therefore should be copied as well.

It's low risk, and hopefully we find it eliminates this crash, in which case I'll upstream into core.

Test Plan: Smoke tested Zeratul

Reviewers: lyahdav, mowang

Reviewed By: lyahdav

Subscribers: eliwhite

Differential Revision: https://phabricator.intern.facebook.com/D28885871

Tasks: T90602856

Signature: 28885871:1622762608:ea6a17208d585ebd6b0668135be47ae914c19a45
christophpurrer pushed a commit to christophpurrer/react-native-macos that referenced this pull request Jan 30, 2022
Summary:
The crash in T90602856 is very similar to one fixed by D22488854 (see discussion [in PR](microsoft#489 (comment))), and it's possible this `replacement` string also suffers from sharing the same backing store as the attributed string (maybe only when the range encompasses the entire string?) and therefore should be copied as well.

It's low risk, and hopefully we find it eliminates this crash, in which case I'll upstream into core.

Test Plan: Smoke tested Zeratul

Reviewers: lyahdav, mowang

Reviewed By: lyahdav

Subscribers: eliwhite

Differential Revision: https://phabricator.intern.facebook.com/D28885871

Tasks: T90602856

Signature: 28885871:1622762608:ea6a17208d585ebd6b0668135be47ae914c19a45
christophpurrer pushed a commit to christophpurrer/react-native-macos that referenced this pull request Mar 5, 2022
Summary:
The crash in T90602856 is very similar to one fixed by D22488854 (see discussion [in PR](microsoft#489 (comment))), and it's possible this `replacement` string also suffers from sharing the same backing store as the attributed string (maybe only when the range encompasses the entire string?) and therefore should be copied as well.

It's low risk, and hopefully we find it eliminates this crash, in which case I'll upstream into core.

Test Plan: Smoke tested Zeratul

Reviewers: lyahdav, mowang

Reviewed By: lyahdav

Subscribers: eliwhite

Differential Revision: https://phabricator.intern.facebook.com/D28885871

Tasks: T90602856

Signature: 28885871:1622762608:ea6a17208d585ebd6b0668135be47ae914c19a45
facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Jul 26, 2022
…w and RCTEventDispatcher

Summary:
A crash encountered in react-native-macOS is very similar to one fixed by microsoft#489 (comment) (see discussion), and it's possible this `replacement` string also suffers from sharing the same backing store as the attributed string (maybe only when the range encompasses the entire string?) and therefore should be copied as well.

Changelog:
[iOS][Fixed] - Possible fix for convertIdToFollyDynamic crash in RCTBaseTextInputView and RCTEventDispatcher

Reviewed By: sammy-SC

Differential Revision: D38064551

fbshipit-source-id: 9c15f2a980155ab3cbb3fde79fcb93b24ee2091a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiline TextInput crashes after buffer has a certain number of characters and they are deleted
2 participants