Crash when multiple servers are available under the same name
Hi everyone! This week I found a strange problem after trying to launch VLC on my Apple TV: It crashed a few milliseconds after displaying my server list.
I have two SMB servers (One AirPort Time Capsule, and another server running Linux). For some reason I do not know yet, VLC was trying to show my server twice on the server's list[1], making an underlying mechanism to incorrectly calculate a difference on an array, and then crashing with an assertion failure coming from UICollectionView
's performBatchUpdates
.
The problem is on this line, and is caused by this block:
^NSString * _Nullable(id <VLCLocalNetworkService> service) {
return [NSString stringWithFormat:@"%@: %@", service.serviceName, service.title];
}
The block fails to satisfy the diff mechanism, since we have two services with the same serviceName
and title
, while GRKArrayDiff
documentation states that the block must be...
(...) A block which is to provide a unique identifier for a given object in either the previous array or current array. This identifier should be the same for elements in the arrays which are to be considered the same, and different for those elements which are to be considered different from eachother.
Although I reckon that having two services with the same serviceName
and title
makes no sense at all, I also think that the way VLC is handling those identifiers is faulty and should be fixed.
So we could patch it in two ways:
a. Simply remove duplicated items
We could sort newNetworkServices
and remove duplicates. This ensures that identityBlock
will always return a unique identifier.
b. Handle "truly" unique identifiers
We could implement a new read-only property to VLCLocalNetworkService
, called uniqueIdentifer
, allowing each class conforming to the protocol to implement their own way to provide their IDs.
For instance, VLCLocalNetworkServiceUPnP
could return the UUID
property from their underlying BasicUPnPDevice
, but other services would be trickier to handle, since they don't have a way to safely distinguish themselves.
Please do notice that even implementing the option b
, we would also need to implement a
.
[1] Perhaps for having two NICs?
I apologise in advance for the (probably) confusing text.