Why is CFNetworking crashing on iOS11

We have an app that is working just fine in iOS 10, but crashes in iOS 11.

I am currently trying to trace the problem, but the first crash is here;


  1. CFDataRef bodyData = CFHTTPMessageCopyBody( message );
  2. CFHTTPMessageSetBody( newMessage, bodyData );
  3. CFRelease( bodyData ); bodyData = NULL;


It seems that I get a nil value from the CFHTTPMessageCopyBody in iOS 11, but not in iOS 10;

From debugger;



iOS 11

(lldb) po message

<CFHTTPMessageRef 0x1c417fbc0(0x1c417fbd0)> { GET request, url /873769144/sec/ENCRYPTED_Television*******_240516_1.mp4 -- http:/

(lldb) po bodyData

<nil>

(lldb) po newMessage

<CFHTTPMessageRef 0x1c4360840(0x1c4360850)> { GET request, url http:/

****



iOS 10

(lldb) po message

<CFHTTPMessageRef 0x170173a40(0x170173a50)> { GET request, url /771278348/sec/ENCRYPTED_Television_**********_240516_1.mp4 -- http:/

(lldb) po bodyData

<>

(lldb) po newMessage

<CFHTTPMessageRef 0x170173b00(0x170173b10)> { GET request, url http://someurl*/sec/ENCRYPTED_Television********_240516_1.mp4 }



I deleted the CFNetwork.framework from the app, and added it again. Just in case. But it didn't help.

Has anything changed in the framework?

The docs for

CFHTTPMessageCopyBody
allow for it to return
NULL
in the case where there’s no body:

A CFData object or NULL if there was a problem creating the object or if the there is no message body.

I think you’ll need to fix your code to allow for this.

What are you using

CFHTTPMessage
for? There are a few places where it’s still a useful API, but most uses are related to
CFHTTPStream
and that’s long been deprecated.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hello guys,


I face the same issue (cf crash logs below), I thought it was solved as it is not the first time I see this issue but when resubtmitting yesterday I still saw the problem:


0 CoreFoundation 0x18140a364 __exceptionPreprocess + 124

1 libobjc.A.dylib 0x180650528 objc_exception_throw + 55

2 CoreFoundation 0x18140a2ac +[NSException raise:format:] + 115

3 CoreFoundation 0x1813f94dc -[NSTaggedPointerString substringWithRange:] + 291

4 Matchers 0x100ba7500 __42-[AppDelegate applicationDidBecomeActive:]_block_invoke + 341248 (AppDelegate.m:613)

5 libdispatch.dylib 0x180d86a14 _dispatch_client_callout + 15

6 libdispatch.dylib 0x180d8a240 dispatch_once_f$VARIANT$mp + 59

7 Matchers 0x100ba748c -[AppDelegate applicationDidBecomeActive:] + 341132 (once.h:84)

8 UIKit 0x18a96c9b4 -[UIApplication _stopDeactivatingForReason:] + 1247

9 UIKit 0x18b2df41c __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 539

10 UIKit 0x18b4783dc _performActionsWithDelayForTransitionContext + 111

11 UIKit 0x18b2df18c -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 251

12 UIKit 0x18b0c378c -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 363

13 UIKit 0x18af652d4 -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:] + 467

14 FrontBoardServices 0x183aceca4 __80-[FBSSceneImpl updater:didUpdateSettings:withDiff:transitionContext:completion:]_block_invoke.362 + 211

15 libdispatch.dylib 0x180d86a14 _dispatch_client_callout + 15

16 libdispatch.dylib 0x180d8e200 _dispatch_block_invoke_direct$VARIANT$mp + 287

17 FrontBoardServices 0x183b027f8 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 35

18 FrontBoardServices 0x183b0249c -[FBSSerialQueue _performNext] + 403

19 FrontBoardServices 0x183b02a38 -[FBSSerialQueue _performNextFromRunLoopSource] + 55

20 CoreFoundation 0x1813b297c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 23

21 CoreFoundation 0x1813b28fc __CFRunLoopDoSource0 + 87

22 CoreFoundation 0x1813b2184 __CFRunLoopDoSources0 + 203

23 CoreFoundation 0x1813afd5c __CFRunLoopRun + 1047

24 CoreFoundation 0x1812cfe58 CFRunLoopRunSpecific + 435

25 GraphicsServices 0x18317cf84 GSEventRunModal + 99

26 UIKit 0x18a94f67c UIApplicationMain + 235

27 Matchers 0x100bfd11c main + 692508 (main.m:17)

28 libdyld.dylib 0x180dec56c start + 3


Is there any workaround to avoid this issue?


Thanks,

Jules

I don’t see any correlation between your crash and ARJ57’s. In your code a block within your app’s

-applicationDidBecomeActive:
method (frame 4) is calling
-substringWithRange:
with parameters that cause it to throw an exception (typically this means the range is out of bounds). I recommend that you symbolicate your crash report (per TN2151) to find the line of code for frame 4, then investigate how it calculates the range it passes to
-substringWithRange:
.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Did you find solution to this problem?

I am also facing this issue. But in my case the returned HTTPBody object is truncated.

Why is CFNetworking crashing on iOS11
 
 
Q