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

Commit e95125a

Browse files
Qxyatcbracken
authored andcommitted
Fix iOS keyboard crash (#10656)
Fixes an iOS crash on physical devices in `-[__NSCFString substringWithRange:]`: range out of bounds. According to Apple's docs for `UITextInput` method `positionFromPosition:(UITextPosition*)position offset:(NSInteger)offset`, this method should return: A custom UITextPosition object that represents the location in a document that is at the specified offset from position. Return nil if the computed text position is less than 0 or greater than the length of the backing string.
1 parent a50ec07 commit e95125a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,12 @@ - (NSUInteger)incrementOffsetPosition:(NSUInteger)position {
433433

434434
- (UITextPosition*)positionFromPosition:(UITextPosition*)position offset:(NSInteger)offset {
435435
NSUInteger offsetPosition = ((FlutterTextPosition*)position).index;
436+
437+
NSInteger newLocation = (NSInteger)offsetPosition + offset;
438+
if (newLocation < 0 || newLocation > (NSInteger)self.text.length) {
439+
return nil;
440+
}
441+
436442
if (offset >= 0) {
437443
for (NSInteger i = 0; i < offset && offsetPosition < self.text.length; ++i)
438444
offsetPosition = [self incrementOffsetPosition:offsetPosition];

0 commit comments

Comments
 (0)