CoreFoundation.CFReadStreamRead readData crash

Hi there,
We see this weird crashes that seem to be caused by a memory issue in CFReadStreamRead. It's happening on iOS 11.4 and iOS 12.1. We cannot related it to any specific activity of the app. Is it a CoreFoundation issue? Any workarounds? Thanks in advance.

OS Version: iPhone OS 11.4.1 (15G77)

Report Version: 104


Exception Type: SIGSEGV

Exception Codes: SEGV_ACCERR at 0x11181bffc

Crashed Thread: 5

  
 
Thread 5 Crashed:
0 libsystem_platform.dylib 0x0000000185002a00 _platform_memmove + 48
1 CoreFoundation 0x00000001852e98b4 dataRead + 108
2 CoreFoundation 0x00000001852d5fac CFReadStreamRead + 480
3 CFNetwork 0x00000001859d9f30 formRead(__CFReadStream*, unsigned char*, long, __CFError**, unsigned char*, void*) + 52
4 CoreFoundation 0x00000001852d6060 CFReadStreamRead + 660
5 CFNetwork 0x0000000185ba31bc HTTPTransaction::RequestBodyStream::_bufferRequestBodyFromStream_offqueue() + 144
6 libdispatch.dylib 0x0000000184cd8a60 _dispatch_client_callout + 12
7 libdispatch.dylib 0x0000000184ce0170 _dispatch_block_invoke_direct$VARIANT$mp + 220
8 CFNetwork 0x0000000185bbbe40 RunloopBlockContext::_invoke_block(void const*, void*) + 32
9 CoreFoundation 0x00000001852ac680 CFArrayApplyFunction + 76
10 CFNetwork 0x0000000185bbbd00 RunloopBlockContext::perform() + 124
11 CFNetwork 0x0000000185bbcec4 MultiplexerSource::perform() + 308
12 CFNetwork 0x0000000185bbcc24 MultiplexerSource::_perform(void*) + 56
13 CoreFoundation 0x000000018538f404 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 20
14 CoreFoundation 0x000000018538ec2c __CFRunLoopDoSources0 + 272
15 CoreFoundation 0x000000018538c79c __CFRunLoopRun + 1200
16 CoreFoundation 0x00000001852acda8 CFRunLoopRunSpecific + 548
17 CFNetwork 0x0000000185bba6e0 -[__CoreSchedulingSetRunnable runForever] + 216
18 Foundation 0x0000000185e31efc __NSThread__start__ + 1036
19 libsystem_pthread.dylib 0x000000018500d220 _pthread_body + 268
20 libsystem_pthread.dylib 0x000000018500d110 _pthread_start + 288
21 libsystem_pthread.dylib 0x000000018500bb10 thread_start + 0


oreFoundation 0x00000001852acda8 CFRunLoopRunSpecific + 548 17 CFNetwork 0x0000000185bba6e0 -[__CoreSchedulingSetRunnable runForever] + 216 18 Foundation 0x0000000185e31efc __NSThread__start__ + 1036 19 libsystem_pthread.dylib 0x000000018500d220 _pthread_body + 268 20 libsystem_pth 0x0000000185bbbe40 RunloopBlockContext::_invoke_block(void const*, void*) + 32 9 CoreFoundation 0x00000001852ac680 CFArrayApplyFunction + 76 10 CFNetwork 0x0000000185bbbd00 RunloopBlockContext::perform() + 124 11 CFNetwork 0x0000000185bbcec4 MultiplexerSource::perform() + 308 12 CFNetwork 0x0000000185bbcc24 MultiplexerSource::_perform(void*) + 56 13 CoreFoundati 0x000000018538ec2c __CFRunLoopDoSources0 + 272 15 CoreFoundation

Replies

It is very likely that you are misusing the function. Please show your code with enough context.

Many thanks for the quick response. Happy to share more context but I'm not sure what function you refer to, we don't call CFReadStreamRead directly. I cannot find anything related in the strack trace. We use pretty much vanila URLSession setup as well as a raw socket connection using `CFStreamCreatePairWithSocketToHost`, `CFNetworkCopyProxiesForAutoConfigurationScript` and few other CF* synchronous functions. Could you point me what kind of API/misuse would cause this type of issue?

eskimo has been actively discouraging people from using those old CF functions for a few years now. Here is a post from 2015 where he specifically recommends a replacement to CFStreamCreatePairWithSocketToHost: https://forums.developer.apple.com/message/187122#187122