Title: [282243] branches/safari-612-branch
Revision
282243
Author
[email protected]
Date
2021-09-09 16:48:17 -0700 (Thu, 09 Sep 2021)

Log Message

Cherry-pick r281792. rdar://problem/82949614

    [Cocoa] Drawing system fallback fonts to canvas causes a crash
    https://bugs.webkit.org/show_bug.cgi?id=229633
    <rdar://problem/81889036>

    Reviewed by Wenson Hsieh.

    Source/WebCore/PAL:

    * pal/spi/cf/CoreTextSPI.h:

    Source/WebKit:

    Dot-prefixed font names don't survive the round-trip through
    CTFontDescriptorCopyAttributes(CTFontCopyFontDescriptor(font)) unless you also
    pass in the kCTFontOptionsSystemUIFont option.

    Tests: fast/text/system-fallback-canvas.html
           fast/text/draw-synthetic-system-bold-font-into-canvas.html

    * Shared/Cocoa/WebCoreArgumentCodersCocoa.mm:
    (IPC::createCTFont):
    (IPC::ArgumentCoder<Ref<WebCore::Font>>::decodePlatformData):

    LayoutTests:

    * fast/text/system-fallback-canvas-expected.txt: Added.
    * fast/text/system-fallback-canvas.html: Added.

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@281792 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Added Paths

Diff

Modified: branches/safari-612-branch/LayoutTests/ChangeLog (282242 => 282243)


--- branches/safari-612-branch/LayoutTests/ChangeLog	2021-09-09 23:39:40 UTC (rev 282242)
+++ branches/safari-612-branch/LayoutTests/ChangeLog	2021-09-09 23:48:17 UTC (rev 282243)
@@ -1,3 +1,49 @@
+2021-09-09  Russell Epstein  <[email protected]>
+
+        Cherry-pick r281792. rdar://problem/82949614
+
+    [Cocoa] Drawing system fallback fonts to canvas causes a crash
+    https://bugs.webkit.org/show_bug.cgi?id=229633
+    <rdar://problem/81889036>
+    
+    Reviewed by Wenson Hsieh.
+    
+    Source/WebCore/PAL:
+    
+    * pal/spi/cf/CoreTextSPI.h:
+    
+    Source/WebKit:
+    
+    Dot-prefixed font names don't survive the round-trip through
+    CTFontDescriptorCopyAttributes(CTFontCopyFontDescriptor(font)) unless you also
+    pass in the kCTFontOptionsSystemUIFont option.
+    
+    Tests: fast/text/system-fallback-canvas.html
+           fast/text/draw-synthetic-system-bold-font-into-canvas.html
+    
+    * Shared/Cocoa/WebCoreArgumentCodersCocoa.mm:
+    (IPC::createCTFont):
+    (IPC::ArgumentCoder<Ref<WebCore::Font>>::decodePlatformData):
+    
+    LayoutTests:
+    
+    * fast/text/system-fallback-canvas-expected.txt: Added.
+    * fast/text/system-fallback-canvas.html: Added.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@281792 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-08-31  Myles C. Maxfield  <[email protected]>
+
+            [Cocoa] Drawing system fallback fonts to canvas causes a crash
+            https://bugs.webkit.org/show_bug.cgi?id=229633
+            <rdar://problem/81889036>
+
+            Reviewed by Wenson Hsieh.
+
+            * fast/text/system-fallback-canvas-expected.txt: Added.
+            * fast/text/system-fallback-canvas.html: Added.
+
 2021-09-01  Russell Epstein  <[email protected]>
 
         Cherry-pick r281848. rdar://problem/82652449

Added: branches/safari-612-branch/LayoutTests/fast/text/draw-synthetic-system-bold-font-into-canvas-expected-mismatch.html (0 => 282243)


--- branches/safari-612-branch/LayoutTests/fast/text/draw-synthetic-system-bold-font-into-canvas-expected-mismatch.html	                        (rev 0)
+++ branches/safari-612-branch/LayoutTests/fast/text/draw-synthetic-system-bold-font-into-canvas-expected-mismatch.html	2021-09-09 23:48:17 UTC (rev 282243)
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+canvas {
+    width: 200px;
+    height: 200px;
+    margin-top: 0;
+}
+</style>
+</head>
+<body>
+<canvas width="400" height="400"></canvas>
+</body>
+</html>

Added: branches/safari-612-branch/LayoutTests/fast/text/draw-synthetic-system-bold-font-into-canvas.html (0 => 282243)


--- branches/safari-612-branch/LayoutTests/fast/text/draw-synthetic-system-bold-font-into-canvas.html	                        (rev 0)
+++ branches/safari-612-branch/LayoutTests/fast/text/draw-synthetic-system-bold-font-into-canvas.html	2021-09-09 23:48:17 UTC (rev 282243)
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+<meta charset="utf8">
+<head>
+<script src=""
+<style>
+canvas {
+    width: 200px;
+    height: 200px;
+    margin-top: 0;
+}
+</style>
+</head>
+<body>
+<canvas width="400" height="400"></canvas>
+</body>
+<script>
+if (window.testRunner)
+    testRunner.waitUntilDone();
+
+addEventListener("load", async () => {
+    let canvas = document.querySelector("canvas");
+    let context = canvas.getContext("2d");
+    context.font = "bold 36px '.AppleSimplifiedChineseFont-Heavy'";
+    context.strokeText("苹果电脑", 40, 40);
+    await UIHelper.renderingUpdate();
+
+    if (window.testRunner)
+        testRunner.notifyDone();
+});
+</script>
+</html>

Added: branches/safari-612-branch/LayoutTests/fast/text/system-fallback-canvas-expected.txt (0 => 282243)


--- branches/safari-612-branch/LayoutTests/fast/text/system-fallback-canvas-expected.txt	                        (rev 0)
+++ branches/safari-612-branch/LayoutTests/fast/text/system-fallback-canvas-expected.txt	2021-09-09 23:48:17 UTC (rev 282243)
@@ -0,0 +1 @@
+This test makes sure that drawing a system fallback font to canvas doesn't crash any process. The test passes if there is no crash.

Added: branches/safari-612-branch/LayoutTests/fast/text/system-fallback-canvas.html (0 => 282243)


--- branches/safari-612-branch/LayoutTests/fast/text/system-fallback-canvas.html	                        (rev 0)
+++ branches/safari-612-branch/LayoutTests/fast/text/system-fallback-canvas.html	2021-09-09 23:48:17 UTC (rev 282243)
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+</head>
+<body>
+This test makes sure that drawing a system fallback font to canvas doesn't crash any process. The test passes if there is no crash.
+<canvas id="canvas" width="400" height="400"></canvas>
+<script>
+if (window.testRunner)
+    testRunner.dumpAsText();
+let canvas = document.getElementById("canvas");
+let context = canvas.getContext("2d");
+context.font = "bold 36px system-ui";
+context.fillText("苹果电脑", 100, 100);
+</script>
+</body>
+</html>

Modified: branches/safari-612-branch/Source/WebCore/PAL/ChangeLog (282242 => 282243)


--- branches/safari-612-branch/Source/WebCore/PAL/ChangeLog	2021-09-09 23:39:40 UTC (rev 282242)
+++ branches/safari-612-branch/Source/WebCore/PAL/ChangeLog	2021-09-09 23:48:17 UTC (rev 282243)
@@ -1,3 +1,48 @@
+2021-09-09  Russell Epstein  <[email protected]>
+
+        Cherry-pick r281792. rdar://problem/82949614
+
+    [Cocoa] Drawing system fallback fonts to canvas causes a crash
+    https://bugs.webkit.org/show_bug.cgi?id=229633
+    <rdar://problem/81889036>
+    
+    Reviewed by Wenson Hsieh.
+    
+    Source/WebCore/PAL:
+    
+    * pal/spi/cf/CoreTextSPI.h:
+    
+    Source/WebKit:
+    
+    Dot-prefixed font names don't survive the round-trip through
+    CTFontDescriptorCopyAttributes(CTFontCopyFontDescriptor(font)) unless you also
+    pass in the kCTFontOptionsSystemUIFont option.
+    
+    Tests: fast/text/system-fallback-canvas.html
+           fast/text/draw-synthetic-system-bold-font-into-canvas.html
+    
+    * Shared/Cocoa/WebCoreArgumentCodersCocoa.mm:
+    (IPC::createCTFont):
+    (IPC::ArgumentCoder<Ref<WebCore::Font>>::decodePlatformData):
+    
+    LayoutTests:
+    
+    * fast/text/system-fallback-canvas-expected.txt: Added.
+    * fast/text/system-fallback-canvas.html: Added.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@281792 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-08-31  Myles C. Maxfield  <[email protected]>
+
+            [Cocoa] Drawing system fallback fonts to canvas causes a crash
+            https://bugs.webkit.org/show_bug.cgi?id=229633
+            <rdar://problem/81889036>
+
+            Reviewed by Wenson Hsieh.
+
+            * pal/spi/cf/CoreTextSPI.h:
+
 2021-08-10  Tim Horton  <[email protected]>
 
         Unreviewed build fix.

Modified: branches/safari-612-branch/Source/WebCore/PAL/pal/spi/cf/CoreTextSPI.h (282242 => 282243)


--- branches/safari-612-branch/Source/WebCore/PAL/pal/spi/cf/CoreTextSPI.h	2021-09-09 23:39:40 UTC (rev 282242)
+++ branches/safari-612-branch/Source/WebCore/PAL/pal/spi/cf/CoreTextSPI.h	2021-09-09 23:48:17 UTC (rev 282243)
@@ -59,6 +59,10 @@
 };
 
 enum {
+    kCTFontOptionsSystemUIFont = 1 << 1,
+};
+
+enum {
     kCTRunStatusHasOrigins = (1 << 4),
 };
 
@@ -148,6 +152,7 @@
 
 bool CTFontDescriptorIsSystemUIFont(CTFontDescriptorRef);
 bool CTFontIsSystemUIFont(CTFontRef);
+CTFontRef CTFontCreateWithFontDescriptorAndOptions(CTFontDescriptorRef, CGFloat size, const CGAffineTransform*, CTFontOptions);
 CTFontRef CTFontCreateForCSS(CFStringRef name, uint16_t weight, CTFontSymbolicTraits, CGFloat size);
 CTFontRef CTFontCreateForCharactersWithLanguage(CTFontRef currentFont, const UTF16Char *characters, CFIndex length, CFStringRef language, CFIndex *coveredLength);
 CTFontRef CTFontCreateForCharactersWithLanguageAndOption(CTFontRef currentFont, const UTF16Char *characters, CFIndex length, CFStringRef language, CTFontFallbackOption, CFIndex *coveredLength);

Modified: branches/safari-612-branch/Source/WebKit/ChangeLog (282242 => 282243)


--- branches/safari-612-branch/Source/WebKit/ChangeLog	2021-09-09 23:39:40 UTC (rev 282242)
+++ branches/safari-612-branch/Source/WebKit/ChangeLog	2021-09-09 23:48:17 UTC (rev 282243)
@@ -1,5 +1,59 @@
 2021-09-09  Russell Epstein  <[email protected]>
 
+        Cherry-pick r281792. rdar://problem/82949614
+
+    [Cocoa] Drawing system fallback fonts to canvas causes a crash
+    https://bugs.webkit.org/show_bug.cgi?id=229633
+    <rdar://problem/81889036>
+    
+    Reviewed by Wenson Hsieh.
+    
+    Source/WebCore/PAL:
+    
+    * pal/spi/cf/CoreTextSPI.h:
+    
+    Source/WebKit:
+    
+    Dot-prefixed font names don't survive the round-trip through
+    CTFontDescriptorCopyAttributes(CTFontCopyFontDescriptor(font)) unless you also
+    pass in the kCTFontOptionsSystemUIFont option.
+    
+    Tests: fast/text/system-fallback-canvas.html
+           fast/text/draw-synthetic-system-bold-font-into-canvas.html
+    
+    * Shared/Cocoa/WebCoreArgumentCodersCocoa.mm:
+    (IPC::createCTFont):
+    (IPC::ArgumentCoder<Ref<WebCore::Font>>::decodePlatformData):
+    
+    LayoutTests:
+    
+    * fast/text/system-fallback-canvas-expected.txt: Added.
+    * fast/text/system-fallback-canvas.html: Added.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@281792 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-08-31  Myles C. Maxfield  <[email protected]>
+
+            [Cocoa] Drawing system fallback fonts to canvas causes a crash
+            https://bugs.webkit.org/show_bug.cgi?id=229633
+            <rdar://problem/81889036>
+
+            Reviewed by Wenson Hsieh.
+
+            Dot-prefixed font names don't survive the round-trip through
+            CTFontDescriptorCopyAttributes(CTFontCopyFontDescriptor(font)) unless you also
+            pass in the kCTFontOptionsSystemUIFont option.
+
+            Tests: fast/text/system-fallback-canvas.html
+                   fast/text/draw-synthetic-system-bold-font-into-canvas.html
+
+            * Shared/Cocoa/WebCoreArgumentCodersCocoa.mm:
+            (IPC::createCTFont):
+            (IPC::ArgumentCoder<Ref<WebCore::Font>>::decodePlatformData):
+
+2021-09-09  Russell Epstein  <[email protected]>
+
         Cherry-pick r282218. rdar://problem/82931375
 
     Implement a WebProcess cap

Modified: branches/safari-612-branch/Source/WebKit/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm (282242 => 282243)


--- branches/safari-612-branch/Source/WebKit/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm	2021-09-09 23:39:40 UTC (rev 282242)
+++ branches/safari-612-branch/Source/WebKit/Shared/Cocoa/WebCoreArgumentCodersCocoa.mm	2021-09-09 23:48:17 UTC (rev 282243)
@@ -501,6 +501,24 @@
     return nullptr;
 }
 
+static RetainPtr<CTFontRef> createCTFont(CFDictionaryRef attributes, float size, const String& referenceURL, const String& postScriptName)
+{
+    if (auto name = static_cast<CFStringRef>(CFDictionaryGetValue(attributes, kCTFontNameAttribute))) {
+        if (CFStringHasPrefix(name, CFSTR("."))) {
+            auto fontDescriptor = adoptCF(CTFontDescriptorCreateWithAttributes(attributes));
+            if (!fontDescriptor)
+                return nullptr;
+            return adoptCF(CTFontCreateWithFontDescriptorAndOptions(fontDescriptor.get(), size, nullptr, kCTFontOptionsSystemUIFont));
+        }
+    }
+
+    auto fontDescriptor = findFontDescriptor(referenceURL, postScriptName);
+    if (!fontDescriptor)
+        return nullptr;
+    fontDescriptor = adoptCF(CTFontDescriptorCreateCopyWithAttributes(fontDescriptor.get(), attributes));
+    return adoptCF(CTFontCreateWithFontDescriptor(fontDescriptor.get(), size, nullptr));
+}
+
 std::optional<WebCore::FontPlatformData> ArgumentCoder<Ref<WebCore::Font>>::decodePlatformData(Decoder& decoder)
 {
     std::optional<WebCore::FontOrientation> orientation;
@@ -580,11 +598,9 @@
     if (!postScriptName)
         return std::nullopt;
 
-    auto fontDescriptor = findFontDescriptor(*referenceURL, *postScriptName);
-    if (!fontDescriptor)
+    auto ctFont = createCTFont(attributes->get(), *size, *referenceURL, *postScriptName);
+    if (!ctFont)
         return std::nullopt;
-    fontDescriptor = adoptCF(CTFontDescriptorCreateCopyWithAttributes(fontDescriptor.get(), attributes->get()));
-    auto ctFont = adoptCF(CTFontCreateWithFontDescriptor(fontDescriptor.get(), *size, nullptr));
 
     return WebCore::FontPlatformData(ctFont.get(), *size, *syntheticBold, *syntheticOblique, *orientation, *widthVariant, *textRenderingMode);
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to