Bug 205217 - Nullptr crash if SVG element if element parent becomes document node
Summary: Nullptr crash if SVG element if element parent becomes document node
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
: 207030 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-12-13 13:40 PST by Sunny He
Modified: 2020-02-04 19:55 PST (History)
18 users (show)

See Also:


Attachments
Patch (4.45 KB, patch)
2019-12-13 13:50 PST, Sunny He
no flags Details | Formatted Diff | Diff
Patch (5.17 KB, patch)
2019-12-13 15:02 PST, Sunny He
no flags Details | Formatted Diff | Diff
Patch (3.18 KB, patch)
2019-12-13 18:34 PST, Sunny He
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sunny He 2019-12-13 13:40:59 PST
Add appropriate null checking to ensure that we don't crash in certain edge cases if an SVG element's parent is set to document.

Crash if the element has a transform:
rdar://49890457

Crash if the element is an SVG <text>
rdar://57075206
Comment 1 Sunny He 2019-12-13 13:50:39 PST
Created attachment 385640 [details]
Patch
Comment 2 Darin Adler 2019-12-13 13:55:03 PST
Comment on attachment 385640 [details]
Patch

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

> Source/WebCore/rendering/svg/RenderSVGText.cpp:375
> -    } else if (m_needsTextMetricsUpdate || SVGRenderSupport::findTreeRootObject(*this)->isLayoutSizeChanged()) {
> +    } else if (m_needsTextMetricsUpdate || (SVGRenderSupport::findTreeRootObject(*this) && SVGRenderSupport::findTreeRootObject(*this)->isLayoutSizeChanged())) {

The word "find" in the function name here is supposed to be a hint that the operation is nontrivial, so I suggest we restructure slightly so we can use a local variable and don’t need to call the function twice. Or rename the function if "find" is a guaranteed-inexpensive operation.
Comment 3 Sunny He 2019-12-13 15:02:57 PST
Created attachment 385646 [details]
Patch
Comment 4 Darin Adler 2019-12-13 17:39:21 PST
Comment on attachment 385646 [details]
Patch

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

> Source/WebCore/rendering/svg/RenderSVGText.cpp:377
> +    } else if (m_needsTextMetricsUpdate) {
> +        RenderSVGRoot* rootObj = SVGRenderSupport::findTreeRootObject(*this);
> +        if (rootObj && rootObj->isLayoutSizeChanged()) {

This implements &&, but in the old code it was ||.
Comment 5 Sunny He 2019-12-13 18:34:16 PST
Created attachment 385667 [details]
Patch
Comment 6 Ryosuke Niwa 2019-12-13 21:53:13 PST
Comment on attachment 385667 [details]
Patch

Looks sane to me.
Comment 7 WebKit Commit Bot 2019-12-13 22:37:39 PST
Comment on attachment 385667 [details]
Patch

Clearing flags on attachment: 385667

Committed r253521: <https://trac.webkit.org/changeset/253521>
Comment 8 WebKit Commit Bot 2019-12-13 22:37:41 PST
All reviewed patches have been landed.  Closing bug.
Comment 9 Said Abou-Hallawa 2019-12-16 09:14:30 PST
Comment on attachment 385667 [details]
Patch

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

> Source/WebCore/ChangeLog:8
> +        Test: svg/dom/replaceChild-document-crash.html

Where is this test? I do not see it in this patch. It also did not land in r253521.
Comment 10 Sunny He 2019-12-16 10:25:59 PST
(In reply to Said Abou-Hallawa from comment #9)
> Comment on attachment 385667 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=385667&action=review
> 
> > Source/WebCore/ChangeLog:8
> > +        Test: svg/dom/replaceChild-document-crash.html
> 
> Where is this test? I do not see it in this patch. It also did not land in
> r253521.

Strange, my local git commit shows that file, but it's missing from the uploaded patch. Created new bug 205282 to track getting these tests in.
Comment 11 Ryosuke Niwa 2020-02-04 19:55:32 PST
*** Bug 207030 has been marked as a duplicate of this bug. ***