Bug 206055 - Decoding an SVG off the main thread causes a crash
Summary: Decoding an SVG off the main thread causes a crash
Alias: None
Product: WebKit
Classification: Unclassified
Component: SVG (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Lord
Keywords: InRadar
Depends on:
Blocks: 183720
  Show dependency treegraph
Reported: 2020-01-10 02:26 PST by Chris Lord
Modified: 2021-05-03 02:30 PDT (History)
16 users (show)

See Also:

Patch (6.74 KB, patch)
2021-04-30 05:09 PDT, Chris Lord
no flags Details | Formatted Diff | Diff
Patch (6.99 KB, patch)
2021-05-03 01:33 PDT, Chris Lord
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Lord 2020-01-10 02:26:14 PST
If you decode an SVG off the main thread via ImageBitmap, this results in a crash. You can test this by enabling offscreen-canvas and running either of these two tests:

Comment 1 Simon Fraser (smfr) 2020-01-13 11:05:20 PST
None of the SVG code is thread safe. You'll need to bounce to the main thread for SVG.
Comment 2 Chris Lord 2021-04-30 05:09:54 PDT
Created attachment 427409 [details]
Comment 3 Chris Lord 2021-04-30 06:40:10 PDT
Comment on attachment 427409 [details]

ImageBitmap obviously doesn't need an actual SVG document, it was only using Image to get the bitmap data. Instead, use BitmapImage directly and bypass the SVG and PDF document image loaders.
Comment 4 Darin Adler 2021-04-30 10:33:11 PDT
Comment on attachment 427409 [details]

View in context: https://bugs.webkit.org/attachment.cgi?id=427409&action=review

> Source/WebCore/html/ImageBitmap.cpp:739
> +    auto image = BitmapImage::create(&observer.get());

The better idiom here is observer.ptr().

> Source/WebCore/html/ImageBitmap.cpp:760
> +    bitmapData->context().drawImage(image.get(), destRect, sourceRectangle.releaseReturnValue(), { interpolationQualityForResizeQuality(options.resizeQuality), imageOrientationForOrientation(options.imageOrientation) });

Not sure we need ".get()" here. Ref typically converts itself to a reference when passing it as an argument.

> Source/WebCore/svg/graphics/SVGImage.cpp:83
> +    ASSERT(isMainThread());

Consider also having this assertion in Image::create itself?

The assertion without a comment seems a little mysterious; not that Iā€™d want a long comment.
Comment 5 Chris Lord 2021-05-03 01:33:46 PDT
Created attachment 427544 [details]
Comment 6 EWS 2021-05-03 02:29:58 PDT
Committed r276895 (237241@main): <https://commits.webkit.org/237241@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 427544 [details].
Comment 7 Radar WebKit Bug Importer 2021-05-03 02:30:18 PDT