Bug 48255 - Stack overflow when there are too many sibling inline boxes
Summary: Stack overflow when there are too many sibling inline boxes
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P3 Normal
Assignee: Yong Li
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-25 11:41 PDT by Yong Li
Modified: 2010-12-15 15:07 PST (History)
4 users (show)

See Also:


Attachments
the patch (1.01 MB, patch)
2010-10-25 11:49 PDT, Yong Li
abarth: review-
Details | Formatted Diff | Diff
updated with much smaller test case (3.08 KB, patch)
2010-11-02 11:23 PDT, Yong Li
eric: review-
Details | Formatted Diff | Diff
Updated (3.50 KB, patch)
2010-12-13 10:00 PST, Yong Li
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yong Li 2010-10-25 11:41:59 PDT
The root reason is this function in InlineBox:

    virtual void setConstructed()
    {
        m_constructed = true;
        if (m_next)
            m_next->setConstructed();
    }

However, it is not very normal that a page contains that many sibling inline boxes. Not sure if it is worth a fix. I'll upload a patch anyway.
Comment 1 Yong Li 2010-10-25 11:49:43 PDT
Created attachment 71778 [details]
the patch

The test case crashes Safari 5 win32.
Comment 2 Adam Barth 2010-10-31 18:36:30 PDT
Comment on attachment 71778 [details]
the patch

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

> LayoutTests/fast/overflow/lots-of-sibling-inline-boxes.html:3
> +Make sure browser doesn't crash with lots of inline boxes in parallel.

Can you generate this test file using document.write instead of having infinite <a> tags in the source?
Comment 3 Yong Li 2010-11-02 08:52:01 PDT
(In reply to comment #2)
> (From update of attachment 71778 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=71778&action=review
> > LayoutTests/fast/overflow/lots-of-sibling-inline-boxes.html:3
> > +Make sure browser doesn't crash with lots of inline boxes in parallel.
> Can you generate this test file using document.write instead of having infinite <a> tags in the source?

Good point. I will give a try
Comment 4 Yong Li 2010-11-02 11:23:56 PDT
Created attachment 72703 [details]
updated with much smaller test case

It needs 130k inline boxes to bring Safari down. So still not certain it is worth doing. Probably it is good for mobile platforms in the case call stack is much smaller than desktop.
Comment 5 Andreas Kling 2010-11-07 20:07:35 PST
Comment on attachment 72703 [details]
updated with much smaller test case

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

> WebCore/rendering/InlineBox.h:165
> -    virtual void setConstructed()
> -    {
> -        m_constructed = true;
> -        if (m_next)
> -            m_next->setConstructed();
> -    }
> +    virtual void setConstructed() { m_constructed = true; }

This looks like a behavior change to me, InlineBox::setConstructed() will no longer affect sibling boxes.
Is this correct (and safe)?

> WebCore/rendering/InlineBox.h:284
> +    InlineBox* next() { return m_next; }

This method should be const.
Comment 6 Yong Li 2010-11-09 07:28:37 PST
(In reply to comment #5)
> (From update of attachment 72703 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=72703&action=review
> > WebCore/rendering/InlineBox.h:165
> > -    virtual void setConstructed()
> > -    {
> > -        m_constructed = true;
> > -        if (m_next)
> > -            m_next->setConstructed();
> > -    }
> > +    virtual void setConstructed() { m_constructed = true; }
> This looks like a behavior change to me, InlineBox::setConstructed() will no longer affect sibling boxes.
> Is this correct (and safe)?

It is safe.

> > WebCore/rendering/InlineBox.h:284
> > +    InlineBox* next() { return m_next; }
> This method should be const.

It is returning a non-const pointer. If we make such methods "const", it is potentially possible that some code gets non-const pointer through const pointer without a const_cast. Are we sure we want to do that?

I think usually we should add another const method when we need it:
const InlineBox* next() const { return m_next; }
Comment 7 Andreas Kling 2010-11-09 07:36:22 PST
Comment on attachment 72703 [details]
updated with much smaller test case

You are right, I jumped the gun here, resetting r?
Comment 8 Eric Seidel (no email) 2010-12-12 02:46:29 PST
Comment on attachment 72703 [details]
updated with much smaller test case

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

This needs an expectation file and should be dump as text.

> LayoutTests/fast/overflow/lots-of-sibling-inline-boxes.html:2
> +<html>
> +<body>

You dont' actually need these. :)

> LayoutTests/fast/overflow/lots-of-sibling-inline-boxes.html:4
> +<script>

This should be dumpAsText().

> LayoutTests/fast/overflow/lots-of-sibling-inline-boxes.html:9
> +</body>
> +</html>

Or these.  EOF newlines are nice for making diff not complain. :)
Comment 9 Yong Li 2010-12-13 10:00:26 PST
Created attachment 76400 [details]
Updated
Comment 10 Darin Adler 2010-12-13 10:27:35 PST
Comment on attachment 76400 [details]
Updated

If our aim is to eliminate unnecessary recursion, it would be nice to walk the entire tree without recursing. It’s good to eliminate recursing for each sibling, yet this still recurses if children in turn have children. The trick is to write a traversal function like Node::traverseNextNode or RenderObject::nextInPreOrder and use it. If we do that we might also not want setConstructed to be a virtual function any more.
Comment 11 Eric Seidel (no email) 2010-12-14 15:14:43 PST
Attachment 76400 [details] was posted by a committer and has review+, assigning to Yong Li for commit.
Comment 12 WebKit Commit Bot 2010-12-15 15:06:53 PST
Comment on attachment 76400 [details]
Updated

Clearing flags on attachment: 76400

Committed r74145: <http://trac.webkit.org/changeset/74145>
Comment 13 WebKit Commit Bot 2010-12-15 15:07:01 PST
All reviewed patches have been landed.  Closing bug.