NSPathControl -setURL: crash on macOS Tahoe

I received the following crash:

Thread 0 Crashed:
libsystem_kernel.dylib        	__pthread_kill + 8
libsystem_pthread.dylib       	pthread_kill + 296 (pthread.c:1721)
 libsystem_c.dylib             	abort + 124 (abort.c:122)
libc++abi.dylib               	__abort_message + 132 (abort_message.cpp:66)
libc++abi.dylib               	demangling_terminate_handler() + 304 (cxa_default_handlers.cpp:76)
libobjc.A.dylib               	_objc_terminate() + 156 (objc-exception.mm:496)
libc++abi.dylib               	std::__terminate(void (*)()) + 16 (cxa_handlers.cpp:59)
libc++abi.dylib               	__cxxabiv1::failed_throw(__cxxabiv1::__cxa_exception*) + 88 (cxa_exception.cpp:152)
libc++abi.dylib               	__cxa_throw + 92 (cxa_exception.cpp:299)
libobjc.A.dylib                objc_exception_throw + 448 (objc-exception.mm:385)
Foundation                    	-[NSConcreteMutableAttributedString initWithString:] + 268 (NSAttributedString.m:1049)
CloudDocs                     	-[BRCloudPathComponentDisplayMetadata initWithDisplayName:suffix:url:icon:] + 180 (BRCloudPathComponentDisplayMetadata.m:75)
CloudDocs                     	-[NSURL(BRCloudPathComponent) br_pathComponentDisplayMetadataWithOptions:]_block_invoke + 516 (BRCloudPathComponentDisplayMetadata.m:292)
CloudDocs                     	-[NSArray(BRAdditions) br_transform:keepNull:] + 228 (NSArray+BRAdditions.m:20)
CloudDocs                     	-[NSURL(BRCloudPathComponent) br_pathComponentDisplayMetadataWithOptions:] + 76 (BRCloudPathComponentDisplayMetadata.m:276)
AppKit                        	-[NSPathCell _autoUpdateCellContents] + 2080 (NSPathCell.m:442)
AppKit                        	-[NSPathCell setURL:] + 76 (NSPathCell.m:599)
AppKit                        	-[NSPathControl setURL:] + 64 (NSPathControl.m:366)

I tried reproducing on my end by passing various URLs in iCloud Drive to an NSPathControl, file reference urls, attempting to evict a URL from iCloud Drive then settings the URL property without luck.

Setting the URL to nil does not crash (the property is nullable). I have no idea how to trigger that code path. Anyone else run into this and have a workaround?

Okay so I can't seem to get an actual URL to cause this crash. Maybe there is a race condition. I wonder if you could crash other apps by evicting files from iCloud at just the right time.

I am able to reproduce it by swizzling BRCloudPathComponentDisplayMetadata's -initWithDisplayName:suffix:url:icon: and calling the original implementation and passing nil for the displayName parameter which then gets passed to NSConcreteMutableAttributedString -initWithString: and crashes. Neat!

Not easy to reproduce 'naturally'. Not sure if there is a way I can intercept the URL before passing it to NSPathControl -setURL: and transform it in a way that avoids this crash but haven't been able to reproduce it on my end naturally so I'm not sure what to look for in the URL. Anyone got any pointers? Otherwise one of these methods is looking like some Pollo Tropical - swizzles on the grill.

CloudDocs -[BRCloudPathComponentDisplayMetadata initWithDisplayName:suffix:url:icon:] + 180 (BRCloudPathComponentDisplayMetadata.m:75)

CloudDocs -[NSURL(BRCloudPathComponent) br_pathComponentDisplayMetadataWithOptions:]_b

Also FB21554951

NSPathControl -setURL: crash on macOS Tahoe
 
 
Q