CGDataProviderCreateWithCFData() hangs on 7.1 when there is no Internet connection available.

Originator:jaredsinclair.rn
Number:rdar://15733650 Date Originated:30-Dec-2013 11:48 PM
Status:Open Resolved:
Product:iOS SDK Product Version:7.1
Classification:Crash/Hang/Data Loss Reproducible:Always
 
Summary:
CGDataProviderCreateWithCFData() hangs on iOS 7.1 when called from within application:didFinishLaunchingWithOptions: and there is no Internet connection available. The application becomes completely unresponsive.

Steps to Reproduce:
0. Enable Airplane mode on your device, then perform the following steps from within application:didFinishLaunchingWithOptions: on the main thread.
1. Create an CGDataRef/NSData instance using font data from an in-memory resource or from data on disk.
2. Create a CGDataProviderRef with the font data from step 1.
3. Attempt to create a font using CGDataProviderCreateWithCFData() and the provider from step 2.
4. The internal implementation of CGDataProviderCreateWithCFData() waits indefinitely for a semaphore that never arrives.
5. The app freezes completely and will not finish launching.

Expected Results:
I expect to get either a valid CGFontRef or an error. Neither occurs because CGDataProviderCreateWithCFData() never returns.

Actual Results:
The internal implementation of CGDataProviderCreateWithCFData() waits indefinitely for a semaphore that never arrives. The main thread is completely blocked.

Regression:
The bug does not occur prior to iOS 7.1, nor does it occur if the Steps to Reproduce are called later on in the app launch sequence (e.g, during the runloop after the runloop in which application:didFinishLaunchingWithOptions: is called). The bug also does not occur if there is an Internet connection available. Repeating the Steps to Reproduce with a good network connection proceeds as expected, successfully creating a CGFontRef.

Notes:
Here is the code I use in the steps above:

- (BOOL)application:(UIApplication *)application 
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

	NSData *inData = <FONT_DATA_HERE>
	CFErrorRef error;
        CGDataProviderRef provider = CGDataProviderCreateWithCFData((CFDataRef)inData);
        CGFontRef font = CGFontCreateWithDataProvider(provider);
        if (! CTFontManagerRegisterGraphicsFont(font, &error)) {
            CFStringRef errorDescription = CFErrorCopyDescription(error);
            NSLog(@"Failed to load font: %@", errorDescription);
            CFRelease(errorDescription);
        }
        CFRelease(font);
        CFRelease(provider);

	return YES;
}

Comments

This bug is still present on iOS 7.1 beta 4 and beta 3.

By jaredsinclair.rn at Jan. 21, 2014, 5:38 p.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!