Title: [250394] trunk/Source/WebKit
Revision
250394
Author
[email protected]
Date
2019-09-26 12:20:22 -0700 (Thu, 26 Sep 2019)

Log Message

Crash under WebPage::beginPrinting when m_printContext becomes null due to synchronous layout
https://bugs.webkit.org/show_bug.cgi?id=202171
<rdar://problem/49731211>

Reviewed by Tim Horton.

Speculatively fix a null pointer dereference crash in WebPage::beginPrinting.

WebPage::beginPrinting creates a PrintContext, stores it in m_printContext, then calls
PrintContext::begin which forces a synchronous, paginated layout. If a post-layout task
executes script, that might result in the WebPage being closed and m_printContext being set
to nullptr.

Guard against this in WebPage::beginPrinting by adding a null check before calling
PrintContext::computePageRects.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::beginPrinting):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (250393 => 250394)


--- trunk/Source/WebKit/ChangeLog	2019-09-26 19:16:40 UTC (rev 250393)
+++ trunk/Source/WebKit/ChangeLog	2019-09-26 19:20:22 UTC (rev 250394)
@@ -1,3 +1,24 @@
+2019-09-26  Andy Estes  <[email protected]>
+
+        Crash under WebPage::beginPrinting when m_printContext becomes null due to synchronous layout
+        https://bugs.webkit.org/show_bug.cgi?id=202171
+        <rdar://problem/49731211>
+
+        Reviewed by Tim Horton.
+
+        Speculatively fix a null pointer dereference crash in WebPage::beginPrinting.
+
+        WebPage::beginPrinting creates a PrintContext, stores it in m_printContext, then calls
+        PrintContext::begin which forces a synchronous, paginated layout. If a post-layout task
+        executes script, that might result in the WebPage being closed and m_printContext being set
+        to nullptr.
+
+        Guard against this in WebPage::beginPrinting by adding a null check before calling
+        PrintContext::computePageRects.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::beginPrinting):
+
 2019-09-26  Kate Cheney  <[email protected]>
 
         Enable LayoutTests using ResourceLoadStatistics SQLite backend (195420)

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (250393 => 250394)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2019-09-26 19:16:40 UTC (rev 250393)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2019-09-26 19:20:22 UTC (rev 250394)
@@ -4660,6 +4660,14 @@
     auto computedPageSize = m_printContext->computedPageSize(FloatSize(printInfo.availablePaperWidth, printInfo.availablePaperHeight), printInfo.margin);
     m_printContext->begin(computedPageSize.width(), computedPageSize.height());
 
+    // PrintContext::begin() performed a synchronous layout which might have executed a
+    // script that closed the WebPage, clearing m_printContext.
+    // See <rdar://problem/49731211> for cases of this happening.
+    if (!m_printContext) {
+        unfreezeLayerTree(LayerTreeFreezeReason::Printing);
+        return;
+    }
+
     float fullPageHeight;
     m_printContext->computePageRects(FloatRect(0, 0, computedPageSize.width(), computedPageSize.height()), 0, 0, printInfo.pageSetupScaleFactor, fullPageHeight, true);
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to