Check nullity of CGColorSpaceCopyICCProfile's return value

Happens when the window is minimized or during the laps of time it
goes to fullscreen, the CGImage size being 1x1.

Issue introduced when adding ICC profile support, see
https://webrtc-review.googlesource.com/c/src/+/133580

Bug: chromium:945468
Change-Id: I65e90eaaa8999578f6127c229376ead219d7a795
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/133708
Reviewed-by: Sergey Ulanov <sergeyu@chromium.org>
Commit-Queue: Julien Isorce <julien.isorce@chromium.org>
Cr-Commit-Position: refs/heads/master@{#27832}
This commit is contained in:
Julien Isorce 2019-04-20 15:03:38 -07:00 committed by Commit Bot
parent e670784747
commit da87648470

View File

@ -74,11 +74,13 @@ std::unique_ptr<DesktopFrameCGImage> DesktopFrameCGImage::CreateFromCGImage(
CGColorSpaceRef cg_color_space = CGImageGetColorSpace(cg_image.get());
if (cg_color_space) {
rtc::ScopedCFTypeRef<CFDataRef> cf_icc_profile(CGColorSpaceCopyICCProfile(cg_color_space));
const uint8_t* data_as_byte =
reinterpret_cast<const uint8_t*>(CFDataGetBytePtr(cf_icc_profile.get()));
const size_t data_size = CFDataGetLength(cf_icc_profile.get());
if (data_as_byte && data_size > 0) {
frame->set_icc_profile(std::vector<uint8_t>(data_as_byte, data_as_byte + data_size));
if (cf_icc_profile) {
const uint8_t* data_as_byte =
reinterpret_cast<const uint8_t*>(CFDataGetBytePtr(cf_icc_profile.get()));
const size_t data_size = CFDataGetLength(cf_icc_profile.get());
if (data_as_byte && data_size > 0) {
frame->set_icc_profile(std::vector<uint8_t>(data_as_byte, data_as_byte + data_size));
}
}
}