REPLAY-1892 Sanitize invalid CGColor
values
#1373
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What and why?
📦 This PR adds a guard logic in SR to prevent it from crashing the app if the assumed value of
view.layer.borderColor
is not a validCGColor
object.Such situation is likely possible in apps that leverage User Defined Runtime Attributes and do it wrong like in this example:
Although the
layer.borderColor
seems to be set properly, at runtime it is resolved toUIDynamicCatalogSystemColor
at runtime, which isn't compatible withCGColor
. Callinglayer.borderColor?.alpha
in such case will crash the app. Interestingly, this seems to only impactview.layer
properties as they useCG*
types. Settingview.backgroundColor
this way will work becauseUIKit
is smart enough to resolveUIColor
properly.We consider this likely and possible, hence we want to prevent SR from causing crashes by adding safety check.
How?
Added basic check with
CFGetTypeID(_:)
to guard if thetypeID
of received CGColor is indeedCGColor.typeID
.The fact that view attribtues are captured in with immutable
ViewAttributes
construct helped to centralise this check. Added second sanity check in thehexString(from:)
logic, which is the only place where we query assumedCGColor
objects.Review checklist
Custom CI job configuration (optional)