<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[168448] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/168448">168448</a></dd>
<dt>Author</dt> <dd>stavila@adobe.com</dd>
<dt>Date</dt> <dd>2014-05-07 15:48:31 -0700 (Wed, 07 May 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Use after free in WebCore::RenderObject::nextSibling / WebCore::RenderBoxModelObject::moveChildrenTo
https://bugs.webkit.org/show_bug.cgi?id=132625
Reviewed by David Hyatt.
Source/WebCore:
Fixed problem with dynamically inserting first letter elements.
Test: fast/multicol/newmulticol/first-letter-create.html
* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::getFirstLetter):
(WebCore::RenderBlock::updateFirstLetter):
* rendering/RenderBlock.h:
* rendering/RenderBoxModelObject.cpp:
(WebCore::RenderBoxModelObject::moveChildrenTo):
LayoutTests:
Added test for special case which might cause use after free.
* fast/multicol/newmulticol/first-letter-create-expected.html: Added.
* fast/multicol/newmulticol/first-letter-create.html: Added.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderBlockcpp">trunk/Source/WebCore/rendering/RenderBlock.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderBlockh">trunk/Source/WebCore/rendering/RenderBlock.h</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderBoxModelObjectcpp">trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderTextFragmenth">trunk/Source/WebCore/rendering/RenderTextFragment.h</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastmulticolnewmulticolfirstlettercreateexpectedhtml">trunk/LayoutTests/fast/multicol/newmulticol/first-letter-create-expected.html</a></li>
<li><a href="#trunkLayoutTestsfastmulticolnewmulticolfirstlettercreatehtml">trunk/LayoutTests/fast/multicol/newmulticol/first-letter-create.html</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (168447 => 168448)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-05-07 22:42:46 UTC (rev 168447)
+++ trunk/LayoutTests/ChangeLog        2014-05-07 22:48:31 UTC (rev 168448)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2014-05-07 Radu Stavila <stavila@adobe.com>
+
+ Use after free in WebCore::RenderObject::nextSibling / WebCore::RenderBoxModelObject::moveChildrenTo
+ https://bugs.webkit.org/show_bug.cgi?id=132625
+
+ Reviewed by David Hyatt.
+
+ Added test for special case which might cause use after free.
+
+ * fast/multicol/newmulticol/first-letter-create-expected.html: Added.
+ * fast/multicol/newmulticol/first-letter-create.html: Added.
+
</ins><span class="cx"> 2014-05-07 Chris Fleizach <cfleizach@apple.com>
</span><span class="cx">
</span><span class="cx"> AX: aria-expanded changes are not communicated to clients
</span></span></pre></div>
<a id="trunkLayoutTestsfastmulticolnewmulticolfirstlettercreateexpectedhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/multicol/newmulticol/first-letter-create-expected.html (0 => 168448)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/multicol/newmulticol/first-letter-create-expected.html         (rev 0)
+++ trunk/LayoutTests/fast/multicol/newmulticol/first-letter-create-expected.html        2014-05-07 22:48:31 UTC (rev 168448)
</span><span class="lines">@@ -0,0 +1,36 @@
</span><ins>+<!-- This test passes if it doesn't crash - https://bugs.webkit.org/show_bug.cgi?id=132625 -->
+
+<style>
+ .f::first-letter { color: green }
+</style>
+
+<script>
+ window.onload = function()
+ {
+ var lst = document.getElementsByClassName("d");
+ for (var i = 0; i < lst.length; ++i)
+ lst[i].insertBefore(document.createTextNode("Text"), lst[i].firstChild);
+ }
+</script>
+
+<table>
+ <tr>
+ <td class="f d">More Text</td>
+ </tr>
+</table>
+
+<script>
+ var head = document.getElementsByTagName("head")[0];
+ var style = document.createElement("style");
+ style.innerHTML="* { \n\
+ -webkit-animation-name: name5; \n\
+ -webkit-animation-duration: 4s; \n\
+ } \n\
+ @-webkit-keyframes name5 { \n\
+ from { \n\
+ } \n\
+ to { \n\
+ -webkit-columns: 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; \n\
+ ";
+ head.appendChild(style);
+</script>
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkLayoutTestsfastmulticolnewmulticolfirstlettercreatehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/multicol/newmulticol/first-letter-create.html (0 => 168448)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/multicol/newmulticol/first-letter-create.html         (rev 0)
+++ trunk/LayoutTests/fast/multicol/newmulticol/first-letter-create.html        2014-05-07 22:48:31 UTC (rev 168448)
</span><span class="lines">@@ -0,0 +1,36 @@
</span><ins>+<!-- This test passes if it doesn't crash - https://bugs.webkit.org/show_bug.cgi?id=132625 -->
+
+<style>
+ .f::first-letter { color: green }
+</style>
+
+<script>
+ window.onload = function()
+ {
+ var lst = document.getElementsByClassName("d");
+ for (var i = 0; i < lst.length; ++i)
+ lst[i].insertBefore(document.createTextNode("Text"), lst[i].firstChild);
+ }
+</script>
+
+<table class="test">
+ <tr>
+ <td class="f d">More Text</td>
+ </tr>
+</table>
+
+<script>
+ var head = document.getElementsByTagName("head")[0];
+ var style = document.createElement("style");
+ style.innerHTML="* { \n\
+ -webkit-animation-name: name5; \n\
+ -webkit-animation-duration: 4s; \n\
+ } \n\
+ @-webkit-keyframes name5 { \n\
+ from { \n\
+ } \n\
+ to { \n\
+ -webkit-columns: 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111; \n\
+ ";
+ head.appendChild(style);
+</script>
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (168447 => 168448)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-05-07 22:42:46 UTC (rev 168447)
+++ trunk/Source/WebCore/ChangeLog        2014-05-07 22:48:31 UTC (rev 168448)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2014-05-07 Radu Stavila <stavila@adobe.com>
+
+ Use after free in WebCore::RenderObject::nextSibling / WebCore::RenderBoxModelObject::moveChildrenTo
+ https://bugs.webkit.org/show_bug.cgi?id=132625
+
+ Reviewed by David Hyatt.
+
+ Fixed problem with dynamically inserting first letter elements.
+
+ Test: fast/multicol/newmulticol/first-letter-create.html
+
+ * rendering/RenderBlock.cpp:
+ (WebCore::RenderBlock::getFirstLetter):
+ (WebCore::RenderBlock::updateFirstLetter):
+ * rendering/RenderBlock.h:
+ * rendering/RenderBoxModelObject.cpp:
+ (WebCore::RenderBoxModelObject::moveChildrenTo):
+
</ins><span class="cx"> 2014-05-07 Enrica Casucci <enrica@apple.com>
</span><span class="cx">
</span><span class="cx"> WK2: Programatic scroll requests during scroll or zoom animation to reveal focused element are ignored.
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderBlockcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderBlock.cpp (168447 => 168448)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderBlock.cpp        2014-05-07 22:42:46 UTC (rev 168447)
+++ trunk/Source/WebCore/rendering/RenderBlock.cpp        2014-05-07 22:48:31 UTC (rev 168448)
</span><span class="lines">@@ -3555,63 +3555,84 @@
</span><span class="cx"> currentTextChild->destroy();
</span><span class="cx"> }
</span><span class="cx"> }
</span><ins>+
+void RenderBlock::getFirstLetter(RenderObject*& firstLetter, RenderElement*& firstLetterContainer, RenderObject* skipObject)
+{
+ firstLetter = nullptr;
+ firstLetterContainer = nullptr;
</ins><span class="cx">
</span><del>-void RenderBlock::updateFirstLetter()
-{
</del><span class="cx"> if (!document().styleSheetCollection().usesFirstLetterRules())
</span><span class="cx"> return;
</span><ins>+
</ins><span class="cx"> // Don't recur
</span><span class="cx"> if (style().styleType() == FIRST_LETTER)
</span><span class="cx"> return;
</span><del>-
</del><ins>+
</ins><span class="cx"> // FIXME: We need to destroy the first-letter object if it is no longer the first child. Need to find
</span><span class="cx"> // an efficient way to check for that situation though before implementing anything.
</span><del>- RenderElement* firstLetterBlock = findFirstLetterBlock(this);
- if (!firstLetterBlock)
</del><ins>+ firstLetterContainer = findFirstLetterBlock(this);
+ if (!firstLetterContainer)
</ins><span class="cx"> return;
</span><del>-
</del><ins>+
</ins><span class="cx"> // Drill into inlines looking for our first text descendant.
</span><del>- RenderObject* descendant = firstLetterBlock->firstChild();
- while (descendant) {
- if (descendant->isText())
</del><ins>+ firstLetter = firstLetterContainer->firstChild();
+ while (firstLetter) {
+ if (firstLetter->isText()) {
+ if (firstLetter == skipObject) {
+ firstLetter = firstLetter->nextSibling();
+ continue;
+ }
+
</ins><span class="cx"> break;
</span><del>- RenderElement& current = toRenderElement(*descendant);
</del><ins>+ }
+
+ RenderElement& current = toRenderElement(*firstLetter);
</ins><span class="cx"> if (current.isListMarker())
</span><del>- descendant = current.nextSibling();
</del><ins>+ firstLetter = current.nextSibling();
</ins><span class="cx"> else if (current.isFloatingOrOutOfFlowPositioned()) {
</span><span class="cx"> if (current.style().styleType() == FIRST_LETTER) {
</span><del>- descendant = current.firstChild();
</del><ins>+ firstLetter = current.firstChild();
</ins><span class="cx"> break;
</span><span class="cx"> }
</span><del>- descendant = current.nextSibling();
</del><ins>+ firstLetter = current.nextSibling();
</ins><span class="cx"> } else if (current.isReplaced() || current.isRenderButton() || current.isMenuList())
</span><span class="cx"> break;
</span><span class="cx"> else if (current.style().hasPseudoStyle(FIRST_LETTER) && current.canHaveGeneratedChildren()) {
</span><span class="cx"> // We found a lower-level node with first-letter, which supersedes the higher-level style
</span><del>- firstLetterBlock = &current;
- descendant = current.firstChild();
</del><ins>+ firstLetterContainer = &current;
+ firstLetter = current.firstChild();
</ins><span class="cx"> } else
</span><del>- descendant = current.firstChild();
</del><ins>+ firstLetter = current.firstChild();
</ins><span class="cx"> }
</span><ins>+
+ if (!firstLetter)
+ firstLetterContainer = nullptr;
+}
</ins><span class="cx">
</span><del>- if (!descendant)
</del><ins>+void RenderBlock::updateFirstLetter()
+{
+ RenderObject* firstLetterObj;
+ RenderElement* firstLetterContainer;
+ getFirstLetter(firstLetterObj, firstLetterContainer);
+
+ if (!firstLetterObj)
</ins><span class="cx"> return;
</span><span class="cx">
</span><span class="cx"> // If the child already has style, then it has already been created, so we just want
</span><span class="cx"> // to update it.
</span><del>- if (descendant->parent()->style().styleType() == FIRST_LETTER) {
- updateFirstLetterStyle(firstLetterBlock, descendant);
</del><ins>+ if (firstLetterObj->parent()->style().styleType() == FIRST_LETTER) {
+ updateFirstLetterStyle(firstLetterContainer, firstLetterObj);
</ins><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- if (!descendant->isText())
</del><ins>+ if (!firstLetterObj->isText())
</ins><span class="cx"> return;
</span><span class="cx">
</span><span class="cx"> // Our layout state is not valid for the repaints we are going to trigger by
</span><span class="cx"> // adding and removing children of firstLetterContainer.
</span><span class="cx"> LayoutStateDisabler layoutStateDisabler(&view());
</span><span class="cx">
</span><del>- createFirstLetterRenderer(firstLetterBlock, toRenderText(descendant));
</del><ins>+ createFirstLetterRenderer(firstLetterContainer, toRenderText(firstLetterObj));
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> LayoutUnit RenderBlock::paginationStrut() const
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderBlockh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderBlock.h (168447 => 168448)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderBlock.h        2014-05-07 22:42:46 UTC (rev 168447)
+++ trunk/Source/WebCore/rendering/RenderBlock.h        2014-05-07 22:48:31 UTC (rev 168448)
</span><span class="lines">@@ -260,6 +260,7 @@
</span><span class="cx"> LayoutUnit collapsedMarginAfterForChild(const RenderBox& child) const;
</span><span class="cx">
</span><span class="cx"> virtual void updateFirstLetter();
</span><ins>+ void getFirstLetter(RenderObject*& firstLetter, RenderElement*& firstLetterContainer, RenderObject* skipObject = nullptr);
</ins><span class="cx">
</span><span class="cx"> virtual void scrollbarsChanged(bool /*horizontalScrollbarChanged*/, bool /*verticalScrollbarChanged*/) { }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderBoxModelObjectcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp (168447 => 168448)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp        2014-05-07 22:42:46 UTC (rev 168447)
+++ trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp        2014-05-07 22:48:31 UTC (rev 168448)
</span><span class="lines">@@ -48,6 +48,8 @@
</span><span class="cx"> #include "RenderNamedFlowThread.h"
</span><span class="cx"> #include "RenderRegion.h"
</span><span class="cx"> #include "RenderTable.h"
</span><ins>+#include "RenderText.h"
+#include "RenderTextFragment.h"
</ins><span class="cx"> #include "RenderView.h"
</span><span class="cx"> #include "ScrollingConstraints.h"
</span><span class="cx"> #include "Settings.h"
</span><span class="lines">@@ -2693,6 +2695,22 @@
</span><span class="cx"> for (RenderObject* child = startChild; child && child != endChild; ) {
</span><span class="cx"> // Save our next sibling as moveChildTo will clear it.
</span><span class="cx"> RenderObject* nextSibling = child->nextSibling();
</span><ins>+
+ // Check to make sure we're not saving the firstLetter as the nextSibling.
+ // When the |child| object will be moved, its firstLetter will be recreated,
+ // so saving it now in nextSibling would let us with a destroyed object.
+ if (child->isText() && toRenderText(child)->isTextFragment() && nextSibling && nextSibling->isText()) {
+ RenderObject* firstLetterObj = nullptr;
+ if (RenderBlock* block = toRenderTextFragment(child)->blockForAccompanyingFirstLetter()) {
+ RenderElement* firstLetterContainer = nullptr;
+ block->getFirstLetter(firstLetterObj, firstLetterContainer, child);
+ }
+
+ // This is the first letter, skip it.
+ if (firstLetterObj == nextSibling)
+ nextSibling = nextSibling->nextSibling();
+ }
+
</ins><span class="cx"> moveChildTo(toBoxModelObject, child, beforeChild, fullRemoveInsert);
</span><span class="cx"> child = nextSibling;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderTextFragmenth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderTextFragment.h (168447 => 168448)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderTextFragment.h        2014-05-07 22:42:46 UTC (rev 168447)
+++ trunk/Source/WebCore/rendering/RenderTextFragment.h        2014-05-07 22:48:31 UTC (rev 168448)
</span><span class="lines">@@ -48,6 +48,8 @@
</span><span class="cx">
</span><span class="cx"> RenderBoxModelObject* firstLetter() const { return m_firstLetter; }
</span><span class="cx"> void setFirstLetter(RenderBoxModelObject& firstLetter) { m_firstLetter = &firstLetter; }
</span><ins>+
+ RenderBlock* blockForAccompanyingFirstLetter();
</ins><span class="cx">
</span><span class="cx"> StringImpl* contentString() const { return m_contentString.impl(); }
</span><span class="cx">
</span><span class="lines">@@ -61,7 +63,6 @@
</span><span class="cx"> virtual void willBeDestroyed() override;
</span><span class="cx">
</span><span class="cx"> virtual UChar previousCharacter() const override;
</span><del>- RenderBlock* blockForAccompanyingFirstLetter();
</del><span class="cx">
</span><span class="cx"> unsigned m_start;
</span><span class="cx"> unsigned m_end;
</span></span></pre>
</div>
</div>
</body>
</html>