Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS11 Crash in NSMutableRLEArray replaceObjectsInRange:withObject:length:: Out of bounds

Our App Find a Foundation crash, only in iOS11. How to solve it ?

Fatal Exception: NSRangeException
NSMutableRLEArray replaceObjectsInRange:withObject:length:: Out of bounds

0  CoreFoundation                 0x184f8bd38 __exceptionPreprocess
1  libobjc.A.dylib                0x1844a0528 objc_exception_throw
2  CoreFoundation                 0x184f8bc80 -[NSException initWithCoder:]
3  Foundation                     0x18587c168 -[NSMutableRLEArray replaceObjectsInRange:withObject:length:]
4  Foundation                     0x18588262c -[NSConcreteMutableAttributedString replaceCharactersInRange:withAttributedString:]
5  CoreFoundation                 0x184e65bec -[__NSArrayM enumerateObjectsWithOptions:usingBlock:]
6  UIKit                          0x18ec677b8 -[UILayoutManagerBasedDraggableGeometry draggableObjectsForTextRange:]
like image 912
Benson Chen Avatar asked Oct 26 '17 03:10

Benson Chen


1 Answers

I could reproduce it in iOS 13.0 beta 4 with a sample app showing a UITextView with a special attributed string including a link. It crashes when tap-holding or dragging the link.

NSMutableAttributedString *aString = [[NSMutableAttributedString alloc] initWithString:@""];

NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
attachment.image = [[UIImage imageNamed:@"weblink"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
attachment.bounds = CGRectMake(0, 0, 15, 15);
[aString appendAttributedString:[NSAttributedString attributedStringWithAttachment:attachment]];

[aString appendAttributedString:[[NSAttributedString alloc] initWithString:@"  More Information"]];
[aString addAttribute:NSLinkAttributeName value:[NSURL URLWithString:@"https://www.apple.com"] range:NSMakeRange(0, aString.length)];

self.textView.attributedText = aString;

Filed on  Feedback Assistant as FB6738178.

like image 112
Ortwin Gentz Avatar answered Nov 04 '22 20:11

Ortwin Gentz