Skip to content

Commit 8b174a5

Browse files
Possible fix for convertIdToFollyDynamic crash in RCTBaseTextInputView 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
1 parent 4cbd263 commit 8b174a5

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Libraries/Text/TextInput/RCTBaseTextInputView.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,8 @@ - (NSString *)textInputShouldChangeText:(NSString *)text inRange:(NSRange)range
439439

440440
if (_onTextInput) {
441441
_onTextInput(@{
442-
@"text": text,
442+
// We copy the string here because if it's a mutable string it may get released before we stop using it on a different thread, causing a crash.
443+
@"text": [text copy],
443444
@"previousText": previousText,
444445
@"range": @{
445446
@"start": @(range.location),

React/CoreModules/RCTEventDispatcher.mm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ - (void)sendTextEventWithType:(RCTTextEventType)type
8686
}];
8787

8888
if (text) {
89-
body[@"text"] = text;
89+
// We copy the string here because if it's a mutable string it may get released before we dispatch the event on a
90+
// different thread, causing a crash.
91+
body[@"text"] = [text copy];
9092
}
9193

9294
if (key) {
@@ -103,7 +105,9 @@ - (void)sendTextEventWithType:(RCTTextEventType)type
103105
break;
104106
}
105107
}
106-
body[@"key"] = key;
108+
// We copy the string here because if it's a mutable string it may get released before we dispatch the event on a
109+
// different thread, causing a crash.
110+
body[@"key"] = [key copy];
107111
}
108112

109113
RCTComponentEvent *event = [[RCTComponentEvent alloc] initWithName:events[type] viewTag:reactTag body:body];

0 commit comments

Comments
 (0)