Crash in UITextView when URLifying text (in -doURLificationOnDocument)

Originator:sebastian
Number:rdar://15223268 Date Originated:14-Oct-2013
Status:Open Resolved:
Product:iOS SDK Product Version:iOS 7.0.2
Classification:Crash Reproducible:Rarely
 
Summary:
I've received many crash reports from users of our apps pointing to a SIGABRT crash in TextKit. It is an NSArray out of bounds exception in the method doURLificationOnDocument in the class DDTextKitOperation where it tries to add an attribute to an NSAttributedString. I suspect this happens in some cases when UITextView tries to detect URLs in a UITextView using data detectors and gets the substring range wrong.

I have seen very strange behavior on iOS 7 with UITextView not adding the highlight attribute the right character ranges for URLs/phone numbers, so this might be related. I've attached a video of this behavior, along with the crash report.

Steps to Reproduce:
Not reproducible, only reported through customer crash reports. Please find the crash report attached.

Expected Results:
UITextView should handle the text ranges properly and not crash.

Actual Results:
UITextView causes the app to crash.

Version:
iOS 7.0.2

Notes:


Configuration:
We have seen these crash reports from all types of devices capable of running iOS 6 and above, including iPhone 5, iPhone 4S, iPad (3rd gen) etc.

Comments

Happened something similar to me.

Have you fully initialized the UITextView from your ViewController using next configuration?

hashtagTextStore = [LVHashtagTextStorage new]; NSLayoutManager layoutManager = [NSLayoutManager new]; [hashtagTextStore addLayoutManager: layoutManager]; NSTextContainer textContainer = [[NSTextContainer alloc] initWithSize: CGSizeZero]; [layoutManager addTextContainer: textContainer];

LVTextFieldTest* productDescription = [[LVTextFieldTest alloc] initWithFrame:CGRectMake(15, 400, 300, 100)
                                                               textContainer:textContainer;
[_containerView addSubview:productDescription];

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!