Bug 265000 - FontFace with data: URI crashes Worker
Summary: FontFace with data: URI crashes Worker
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: Safari Technology Preview
Hardware: Mac (Apple Silicon) macOS 14
: P2 Normal
Assignee: youenn fablet
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-11-16 19:04 PST by Jacob Bandes-Storch
Modified: 2023-11-28 07:44 PST (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.