Stack overflow in -[NSString(NSURLUtilities) stringByAddingPercentEncodingWithAllowedCharacters:]

Number:rdar://20404230 Date Originated:02-Apr-2015 11:30 PM
Status:Open Resolved:Duplicate of 18919024 (Closed)
Product:iOS SDK Product Version:
Classification:Crash/Hang/Data Loss Reproducible:Always
Method -[NSString(NSURLUtilities) stringByAddingPercentEncodingWithAllowedCharacters:] has a stack overflow issue, which can be reproduced with some strings containing hieroglyphs. In these cases __stack_chk_fail will abort the application when building for arm64 architectire, and stack will be corrupted when building for armv7.

Steps to Reproduce:
1. Download sample from
2. Run the application (under release configuration, on armv7 in debug it may corrupt stack without a crash)

Expected Results:
Test functions working with strings complete correctly.

Actual Results:
Application crashes.

iOS 8.2 (12D508)

Application contains 2 test functions. In the first case I stumbled myself, and the second was found while googling for the problem. These tests has a different impact on the stack, and the first one may corrupt data without an immediate crash on armv7.

Function CFURLCreateStringByAddingPercentEscapes performs escaping without crashes.

iPhone 6 64GB

'test.crash' was successfully uploaded.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at 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!