Printing a string containing special charecters with NSLog will crash on swift

Originator:shai.shamir
Number:rdar://25265884 Date Originated:21-Mar-2016 11:02 AM
Status:Closed Resolved:
Product:SDK Product Version:iOS 9.0
Classification:UI/Usability Reproducible:Always
 
Summary:
When printing a string containing special characters with NSLog where the variable is embedded into the string will cause the App to crash if the string contains specific characters (used in NSLog to indicate parameters). In Objective-C such error won’t happen

Steps to Reproduce:
<Method A>
1. Run the sample code on a device.
2. Click on the “Swift Sample” button.
3. Click on “Print NSLog” button.
4. Observe the crash

<Method B>
1. Run the sample code on a device set to airmail mode (the no network is to simulate no network so we’ll get a throws with and error).
2. Click on the “Swift Sample” button.
3. Click on “NSError Sample” button.
4. Observe the crash

Expected Results:
<Method A>
1. The App should print the part of the string that is readable (like Objective-C does)

<Method B>
1. The NSError should be printed with the userInfo (as happen on Objective-C).

Actual Results:
<Method A & B>
1. The app crash with “EXC_BAD_ACCESS (code=1, address=0x0)” error

Regression:
On objective -C is is possible to print such strings with NSLog both NSString or NSError containing a userInfo with such string.

Notes:
We’ve experienced this crash on our live system with many thousands of crashes, we issued a fix using a specific NSError parsing to prevent the special characters passed to NSLog.

Comments

Apple response

don't do it...

By shai.shamir at Dec. 13, 2016, 11:24 a.m. (reply...)

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!