Skip to content

Commit

Permalink
[DisplayLink] Semi-speculative fix for crasher in CVCGDL::getDisplayT…
Browse files Browse the repository at this point in the history
…imes

This patch applies a workaround discovered by mozilla to avoid crashes
in CVCGDisplayLink::getDisplayTimes(). The call to
CVDisplayLinkCreateWithCGDisplay() can sometimes tickle a bug that
will lead to a crash. By checking another condition we can detect the
error state and avoid a crash.

Bug: 1218720
Change-Id: Ic7e54d8a03d05143d6e9f54f26ebd79277cca934
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3217658
Reviewed-by: Avi Drissman <avi@chromium.org>
Commit-Queue: Jayson Adams <shrike@chromium.org>
Cr-Commit-Position: refs/heads/main@{#930712}
  • Loading branch information
Jayson Adams authored and Chromium LUCI CQ committed Oct 12, 2021
1 parent 0628ae8 commit 5959b23
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion ui/display/mac/display_link_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,25 @@ scoped_refptr<DisplayLinkMac> DisplayLinkMac::GetForDisplay(
ret = CVDisplayLinkCreateWithCGDisplay(display_id,
display_link.InitializeInto());
if (ret != kCVReturnSuccess) {
LOG(ERROR) << "CVDisplayLinkCreateWithActiveCGDisplays failed: " << ret;
LOG(ERROR) << "CVDisplayLinkCreateWithCGDisplay failed: " << ret;
return nullptr;
}

// Workaround for bug https://crbug.com/1218720. According to
// https://hg.mozilla.org/releases/mozilla-esr68/rev/db0628eadb86,
// CVDisplayLinkCreateWithCGDisplays()
// (called by CVDisplayLinkCreateWithCGDisplay()) sometimes
// creates a CVDisplayLinkRef with an uninitialized (nulled) internal
// pointer. If we continue to use this CVDisplayLinkRef, we will
// eventually crash in CVCGDisplayLink::getDisplayTimes(), where the
// internal pointer is dereferenced. Fortunately, when this happens
// another internal variable is also left uninitialized (zeroed),
// which is accessible via CVDisplayLinkGetCurrentCGDisplay(). In
// normal conditions the current display is never zero.
if ((ret == kCVReturnSuccess) &&
(CVDisplayLinkGetCurrentCGDisplay(display_link) == 0)) {
LOG(ERROR)
<< "CVDisplayLinkCreateWithCGDisplay failed (no current display)";
return nullptr;
}

Expand Down

0 comments on commit 5959b23

Please sign in to comment.