Bug 265000

Summary: FontFace with data: URI crashes Worker
Product: WebKit Reporter: Jacob Bandes-Storch <jacob>
Component: New BugsAssignee: youenn fablet <youennf>
Status: RESOLVED FIXED    
Severity: Normal CC: fantasai.bugs, mattwoodrow, vitor.roriz, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: Safari Technology Preview   
Hardware: Mac (Apple Silicon)   
OS: macOS 14   

Description Jacob Bandes-Storch 2023-11-16 19:04:30 PST
Steps to reproduce:
Tested in Safari 17.1 (19616.2.9.11.7) and Technology Preview (Safari 17.4, WebKit 19618.1.5.2)

1. Create a HTML file with the following content:

    <script>
    new Worker(URL.createObjectURL(new Blob([`(async()=>{
    try {
        await new FontFace("ABC", "url(data:font/woff2,abcd) format('woff2')").load().catch(e=>console.error("rejected",e));
        console.log("done")
    } catch(e) {
        console.error("caught",e)
    }
    })()`])))
    </script>

2. Load the page, open the console and see the following output:

    [Error] Cannot load data:font/woff2,abcd.
    [Error] Failed to load resource: Cross origin requests are not allowed when using same-origin fetch mode. (data:font/woff2,abcd, line 0)

Notice that the "rejected", "caught", and "done" log messages do not appear -- the Worker seems to be completely dead.


Expected behavior:
- Ideally, this method of font loading would just work.
- If loading the data: URL is not permissible, then the error should be catchable via .catch() or try/catch, it should not break the entire Worker.

Workaround:
- Using fetch() to load the data: url and passing an ArrayBuffer to the FontFace constructor seems to be a valid workaround. (example: https://github.com/foxglove/studio/pull/7139)
Comment 1 youenn fablet 2023-11-20 02:12:54 PST
<rdar://118546120>
Comment 2 youenn fablet 2023-11-20 04:08:35 PST
It might be the promise never rejects/resolves.
Comment 3 youenn fablet 2023-11-20 06:40:07 PST
Pull request: https://github.com/WebKit/WebKit/pull/20742
Comment 4 Jacob Bandes-Storch 2023-11-20 22:34:17 PST
Yes, good catch, I guess the `await` in my sample code was a mistake and the worker is not broken :)  Thank you for the quick fix!
Comment 5 EWS 2023-11-28 07:44:06 PST
Committed 271213@main (b1f4d8147c3c): <https://commits.webkit.org/271213@main>

Reviewed commits have been landed. Closing PR #20742 and removing active labels.