[HtmlUnit] [htmlunit:bugs] #1688 Infinite Loop in DomNode.insertBefore

RBRi via HtmlUnit-develop <[email protected]> Wed, 10 Apr 2019 17:37:13 -0000
Newsgroups gmane.comp.java.htmlunit.devel
Message-ID </p/htmlunit/bugs/1688/151acebeb978cbe3bc78474bd9dd4a0a2f0f80a4.bugs@htmlunit.p.sourceforge.net>
This is a multi-part message in MIME format.
--===============6065390354260000050==
Content-Type: multipart/related;
 boundary="===============4828770267778803433=="

This is a multi-part message in MIME format.
--===============4828770267778803433==
Content-Type: multipart/alternative;
 boundary="===============3426275047368595469=="
MIME-Version: 1.0

--===============3426275047368595469==
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit

Sorry no feedback since years, will close this.


---

** [bugs:#1688] Infinite Loop in DomNode.insertBefore**

**Status:** open
**Group:** Latest SVN
**Created:** Fri May 22, 2015 08:04 PM UTC by William Walker
**Last Updated:** Mon Oct 10, 2016 02:07 PM UTC
**Owner:** nobody


Have had HtmlUnit hang up on me executing some web pages.  Below is an example url.

https://www.tablespoon.com/profile/RailNewsletterCTA?parentUrl=%252frecipes%252fcookie-stuffed-brownie-cupcakes%252f3d4d01f7-72cc-434a-ac13-f2f19c3379aa%252f%253fnicam2%253dEmail%2526nichn2%253dCore%2526niseg2%253dTBSP%2526nicreatID2%253dTBSP_05_10_2015%2526utm_source%253dEmail_newsletter%2526utm_medium%253demail%2526utm_campaign%253dTBSP_05_10_2015&disablePageView=1

After tracing into code the problem occurs when insertBefore is called and (newChild instanceof DomDocumentFragment)==true AND fragment.getChildren is not empty.  In my case, the insertBefore is occuring on the same node list that it is iterating against so the iteration goes on forever.

DomNode.java

~~~~~~~~~~~~~~~~~~~~~~~~~~~~
969:    public Node insertBefore(final Node newChild, final Node refChild) {
        if (newChild instanceof DomDocumentFragment) {
            final DomDocumentFragment fragment = (DomDocumentFragment) newChild;
            for (final DomNode child : fragment.getChildren()) {
                insertBefore(child, refChild);
            }
        }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~


---

Sent from sourceforge.net because [email protected] is subscribed to https://sourceforge.net/p/htmlunit/bugs/

To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/htmlunit/admin/bugs/options.  Or, if this is a mailing list, you can unsubscribe from the mailing list.
--===============3426275047368595469==
MIME-Version: 1.0
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: 7bit

<div class="markdown_content"><p>Sorry no feedback since years, will close this.</p>
<hr/>
<p><strong> <a class="alink" href="https://sourceforge.net/p/htmlunit/bugs/1688/">[bugs:#1688]</a> Infinite Loop in DomNode.insertBefore</strong></p>
<p><strong>Status:</strong> open<br/>
<strong>Group:</strong> Latest SVN<br/>
<strong>Created:</strong> Fri May 22, 2015 08:04 PM UTC by William Walker<br/>
<strong>Last Updated:</strong> Mon Oct 10, 2016 02:07 PM UTC<br/>
<strong>Owner:</strong> nobody</p>
<p>Have had HtmlUnit hang up on me executing some web pages.  Below is an example url.</p>
<p><a href="https://www.tablespoon.com/profile/RailNewsletterCTA?parentUrl=%252frecipes%252fcookie-stuffed-brownie-cupcakes%252f3d4d01f7-72cc-434a-ac13-f2f19c3379aa%252f%253fnicam2%253dEmail%2526nichn2%253dCore%2526niseg2%253dTBSP%2526nicreatID2%253dTBSP_05_10_2015%2526utm_source%253dEmail_newsletter%2526utm_medium%253demail%2526utm_campaign%253dTBSP_05_10_2015&amp;disablePageView=1" rel="nofollow">https://www.tablespoon.com/profile/RailNewsletterCTA?parentUrl=%252frecipes%252fcookie-stuffed-brownie-cupcakes%252f3d4d01f7-72cc-434a-ac13-f2f19c3379aa%252f%253fnicam2%253dEmail%2526nichn2%253dCore%2526niseg2%253dTBSP%2526nicreatID2%253dTBSP_05_10_2015%2526utm_source%253dEmail_newsletter%2526utm_medium%253demail%2526utm_campaign%253dTBSP_05_10_2015&amp;disablePageView=1</a></p>
<p>After tracing into code the problem occurs when insertBefore is called and (newChild instanceof DomDocumentFragment)==true AND fragment.getChildren is not empty.  In my case, the insertBefore is occuring on the same node list that it is iterating against so the iteration goes on forever.</p>
<p>DomNode.java</p>
<div class="codehilite"><pre><span></span><span class="mi">969</span><span class="o">:</span>    <span class="kd">public</span> <span class="n">Node</span> <span class="n">insertBefore</span><span class="o">(</span><span class="kd">final</span> <span class="n">Node</span> <span class="n">newChild</span><span class="o">,</span> <span class="kd">final</span> <span class="n">Node</span> <span class="n">refChild</span><span class="o">)</span> <span class="o">{</span>
        <span class="k">if</span> <span class="o">(</span><span class="n">newChild</span> <span class="k">instanceof</span> <span class="n">DomDocumentFragment</span><span class="o">)</span> <span class="o">{</span>
            <span class="kd">final</span> <span class="n">DomDocumentFragment</span> <span class="n">fragment</span> <span class="o">=</span> <span class="o">(</span><span class="n">DomDocumentFragment</span><span class="o">)</span> <span class="n">newChild</span><span class="o">;</span>
            <span class="k">for</span> <span class="o">(</span><span class="kd">final</span> <span class="n">DomNode</span> <span class="n">child</span> <span class="o">:</span> <span class="n">fragment</span><span class="o">.</span><span class="na">getChildren</span><span class="o">())</span> <span class="o">{</span>
                <span class="n">insertBefore</span><span class="o">(</span><span class="n">child</span><span class="o">,</span> <span class="n">refChild</span><span class="o">);</span>
            <span class="o">}</span>
        <span class="o">}</span>
</pre></div>


<hr/>
<p>Sent from sourceforge.net because [email protected] is subscribed to <a href="https://sourceforge.net/p/htmlunit/bugs/">https://sourceforge.net/p/htmlunit/bugs/</a></p>
<p>To unsubscribe from further messages, a project admin can change settings at <a href="https://sourceforge.net/p/htmlunit/admin/bugs/options.">https://sourceforge.net/p/htmlunit/admin/bugs/options.</a>  Or, if this is a mailing list, you can unsubscribe from the mailing list.</p></div>
--===============3426275047368595469==--
--===============4828770267778803433==--


--===============6065390354260000050==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--===============6065390354260000050==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
HtmlUnit-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/htmlunit-develop

--===============6065390354260000050==--