Browse Source

mac-avcapture: Fix possible crash if camera uses BGRA format

BGRA or other formats that do not use color primaries will not yield
a valid color primary value. Initializing the CFComparisonResult to a
default value and replacing it only if a non-NULL color primary value
was retrieved avoids a possible crash.
PatTheMav 1 year ago
parent
commit
12d25f9a91
1 changed files with 5 additions and 1 deletions
  1. 5 1
      plugins/mac-avcapture/plugin-properties.m

+ 5 - 1
plugins/mac-avcapture/plugin-properties.m

@@ -422,10 +422,14 @@ bool properties_update_config(OBSAVCapture *capture, obs_properties_t *propertie
 
             // Only iterate over available framerates if input format, color space, and resolution are matching
             if (hasFoundInputFormat && hasFoundColorSpace && hasFoundResolution) {
+                CFComparisonResult isColorPrimaryMatch = kCFCompareEqualTo;
+
                 CFPropertyListRef colorPrimary = CMFormatDescriptionGetExtension(
                     format.formatDescription, kCMFormatDescriptionExtension_ColorPrimaries);
 
-                CFComparisonResult isColorPrimaryMatch = CFStringCompare(colorPrimary, priorColorPrimary, 0);
+                if (colorPrimary) {
+                    isColorPrimaryMatch = CFStringCompare(colorPrimary, priorColorPrimary, 0);
+                }
 
                 if (isColorPrimaryMatch != kCFCompareEqualTo || !hasFoundFramerate) {
                     for (AVFrameRateRange *range in format.videoSupportedFrameRateRanges.reverseObjectEnumerator) {