<!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>[165138] 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/165138">165138</a></dd>
<dt>Author</dt> <dd>ddkilzer@apple.com</dd>
<dt>Date</dt> <dd>2014-03-05 16:05:55 -0800 (Wed, 05 Mar 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fix crash in CompositeEditCommand::cloneParagraphUnderNewElement()
&lt;http://webkit.org/b/129751&gt;
&lt;rdar://problem/16237965&gt;

Reviewed by Jon Honeycutt.

Merged from Blink (patch by Yuta Kitamura):
https://src.chromium.org/viewvc/blink?revision=168160&amp;view=revision
http://crbug.com/345005

    The root cause is CompositeEditCommand::moveParagraphWithClones() passing
    two positions |start| and |end| which do not follow the document order,
    i.e. in some situations |start| is located after |end| because of
    the difference in affinity.

    This patch fixes this crash by normalizing |end| to |start| in such situations.
    It also adds an ASSERT that checks the relationship between |start| and |end|.

Source/WebCore:

Test: editing/execCommand/format-block-crash.html

* editing/CompositeEditCommand.cpp:
(WebCore::CompositeEditCommand::cloneParagraphUnderNewElement):
(WebCore::CompositeEditCommand::moveParagraphWithClones):
* editing/CompositeEditCommand.h:

LayoutTests:

* editing/execCommand/format-block-crash-expected.txt: Added.
* editing/execCommand/format-block-crash.html: Added.
* editing/execCommand/resources/format-block-crash-iframe.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="#trunkSourceWebCoreeditingCompositeEditCommandcpp">trunk/Source/WebCore/editing/CompositeEditCommand.cpp</a></li>
<li><a href="#trunkSourceWebCoreeditingCompositeEditCommandh">trunk/Source/WebCore/editing/CompositeEditCommand.h</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestseditingexecCommandformatblockcrashexpectedtxt">trunk/LayoutTests/editing/execCommand/format-block-crash-expected.txt</a></li>
<li><a href="#trunkLayoutTestseditingexecCommandformatblockcrashhtml">trunk/LayoutTests/editing/execCommand/format-block-crash.html</a></li>
<li><a href="#trunkLayoutTestseditingexecCommandresourcesformatblockcrashiframehtml">trunk/LayoutTests/editing/execCommand/resources/format-block-crash-iframe.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (165137 => 165138)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2014-03-06 00:03:52 UTC (rev 165137)
+++ trunk/LayoutTests/ChangeLog        2014-03-06 00:05:55 UTC (rev 165138)
</span><span class="lines">@@ -1,3 +1,27 @@
</span><ins>+2014-03-05  David Kilzer  &lt;ddkilzer@apple.com&gt;
+
+        Fix crash in CompositeEditCommand::cloneParagraphUnderNewElement()
+        &lt;http://webkit.org/b/129751&gt;
+        &lt;rdar://problem/16237965&gt;
+
+        Reviewed by Jon Honeycutt.
+
+        Merged from Blink (patch by Yuta Kitamura):
+        https://src.chromium.org/viewvc/blink?revision=168160&amp;view=revision
+        http://crbug.com/345005
+
+            The root cause is CompositeEditCommand::moveParagraphWithClones() passing
+            two positions |start| and |end| which do not follow the document order,
+            i.e. in some situations |start| is located after |end| because of
+            the difference in affinity.
+
+            This patch fixes this crash by normalizing |end| to |start| in such situations.
+            It also adds an ASSERT that checks the relationship between |start| and |end|.
+
+        * editing/execCommand/format-block-crash-expected.txt: Added.
+        * editing/execCommand/format-block-crash.html: Added.
+        * editing/execCommand/resources/format-block-crash-iframe.html: Added.
+
</ins><span class="cx"> 2014-03-05  Radu Stavila  &lt;stavila@adobe.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [CSS Regions] Scrollable regions
</span></span></pre></div>
<a id="trunkLayoutTestseditingexecCommandformatblockcrashexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/editing/execCommand/format-block-crash-expected.txt (0 => 165138)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/execCommand/format-block-crash-expected.txt                                (rev 0)
+++ trunk/LayoutTests/editing/execCommand/format-block-crash-expected.txt        2014-03-06 00:05:55 UTC (rev 165138)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+Should not crash if we load a test case from crbug.com/345005.
+
+On success, you will see a series of &quot;PASS&quot; messages, followed by &quot;TEST COMPLETE&quot;.
+
+
+PASS event.data is &quot;FINISH&quot;
+PASS Did not crash.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
</ins></span></pre></div>
<a id="trunkLayoutTestseditingexecCommandformatblockcrashhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/editing/execCommand/format-block-crash.html (0 => 165138)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/execCommand/format-block-crash.html                                (rev 0)
+++ trunk/LayoutTests/editing/execCommand/format-block-crash.html        2014-03-06 00:05:55 UTC (rev 165138)
</span><span class="lines">@@ -0,0 +1,28 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;title&gt;FormatBlock crash&lt;/title&gt;
+&lt;script src=&quot;../../resources/js-test.js&quot;&gt;&lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;script&gt;
+description('Should not crash if we load a test case from crbug.com/345005.');
+
+window.jsTestIsAsync = true;
+
+window.addEventListener('message', didReceiveMessage, false);
+
+var iframe = document.createElement('iframe');
+iframe.src = 'resources/format-block-crash-iframe.html';
+document.body.appendChild(iframe);
+
+function didReceiveMessage(event)
+{
+    shouldBeEqualToString('event.data', 'FINISH');
+    document.body.removeChild(iframe);
+    testPassed('Did not crash.');
+    window.finishJSTest();
+}
+&lt;/script&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestseditingexecCommandresourcesformatblockcrashiframehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/editing/execCommand/resources/format-block-crash-iframe.html (0 => 165138)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/execCommand/resources/format-block-crash-iframe.html                                (rev 0)
+++ trunk/LayoutTests/editing/execCommand/resources/format-block-crash-iframe.html        2014-03-06 00:05:55 UTC (rev 165138)
</span><span class="lines">@@ -0,0 +1,29 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;title&gt;FormatBlock crash test case&lt;/title&gt;
+&lt;/head&gt;
+&lt;!-- This is a minified version of the clusterfuzz test case at https://code.google.com/p/chromium/issues/detail?id=345005 --&gt;
+&lt;body style=&quot;display: table-row;&quot;&gt;
+&lt;script&gt;
+function run()
+{
+    document.designMode = 'on';
+    document.execCommand('SelectAll');
+    document.execCommand('FormatBlock', false, '&lt;' + 'div&gt;');
+    window.setTimeout(notifyFinish, 0);
+}
+
+function notifyFinish()
+{
+    window.parent.postMessage('FINISH', '*');
+}
+
+window.setTimeout(run, 0);
+&lt;/script&gt;
+&lt;span contenteditable=&quot;true&quot; style=&quot;display: table-caption;&quot;&gt;&lt;/span&gt;
+&lt;span&gt;&lt;/span&gt;
+&lt;div style=&quot;display: -webkit-inline-box;&quot;&gt;&lt;span&gt;&lt;span&gt;B&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
+&lt;div&gt;&lt;/div&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (165137 => 165138)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-03-06 00:03:52 UTC (rev 165137)
+++ trunk/Source/WebCore/ChangeLog        2014-03-06 00:05:55 UTC (rev 165138)
</span><span class="lines">@@ -1,3 +1,30 @@
</span><ins>+2014-03-05  David Kilzer  &lt;ddkilzer@apple.com&gt;
+
+        Fix crash in CompositeEditCommand::cloneParagraphUnderNewElement()
+        &lt;http://webkit.org/b/129751&gt;
+        &lt;rdar://problem/16237965&gt;
+
+        Reviewed by Jon Honeycutt.
+
+        Merged from Blink (patch by Yuta Kitamura):
+        https://src.chromium.org/viewvc/blink?revision=168160&amp;view=revision
+        http://crbug.com/345005
+
+            The root cause is CompositeEditCommand::moveParagraphWithClones() passing
+            two positions |start| and |end| which do not follow the document order,
+            i.e. in some situations |start| is located after |end| because of
+            the difference in affinity.
+
+            This patch fixes this crash by normalizing |end| to |start| in such situations.
+            It also adds an ASSERT that checks the relationship between |start| and |end|.
+
+        Test: editing/execCommand/format-block-crash.html
+
+        * editing/CompositeEditCommand.cpp:
+        (WebCore::CompositeEditCommand::cloneParagraphUnderNewElement):
+        (WebCore::CompositeEditCommand::moveParagraphWithClones):
+        * editing/CompositeEditCommand.h:
+
</ins><span class="cx"> 2014-03-05  Radu Stavila  &lt;stavila@adobe.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [CSS Regions] Scrollable regions
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingCompositeEditCommandcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/CompositeEditCommand.cpp (165137 => 165138)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/CompositeEditCommand.cpp        2014-03-06 00:03:52 UTC (rev 165137)
+++ trunk/Source/WebCore/editing/CompositeEditCommand.cpp        2014-03-06 00:05:55 UTC (rev 165138)
</span><span class="lines">@@ -1048,8 +1048,10 @@
</span><span class="cx"> // Clone the paragraph between start and end under blockElement,
</span><span class="cx"> // preserving the hierarchy up to outerNode. 
</span><span class="cx"> 
</span><del>-void CompositeEditCommand::cloneParagraphUnderNewElement(Position&amp; start, Position&amp; end, Node* passedOuterNode, Element* blockElement)
</del><ins>+void CompositeEditCommand::cloneParagraphUnderNewElement(const Position&amp; start, const Position&amp; end, Node* passedOuterNode, Element* blockElement)
</ins><span class="cx"> {
</span><ins>+    ASSERT(comparePositions(start, end) &lt;= 0);
+
</ins><span class="cx">     // First we clone the outerNode
</span><span class="cx">     RefPtr&lt;Node&gt; lastNode;
</span><span class="cx">     RefPtr&lt;Node&gt; outerNode = passedOuterNode;
</span><span class="lines">@@ -1167,7 +1169,7 @@
</span><span class="cx">     // We upstream() the end and downstream() the start so that we don't include collapsed whitespace in the move.
</span><span class="cx">     // When we paste a fragment, spaces after the end and before the start are treated as though they were rendered.
</span><span class="cx">     Position start = startOfParagraphToMove.deepEquivalent().downstream();
</span><del>-    Position end = endOfParagraphToMove.deepEquivalent().upstream();
</del><ins>+    Position end = startOfParagraphToMove == endOfParagraphToMove ? start : endOfParagraphToMove.deepEquivalent().upstream();
</ins><span class="cx"> 
</span><span class="cx">     cloneParagraphUnderNewElement(start, end, outerNode, blockElement);
</span><span class="cx">       
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingCompositeEditCommandh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/CompositeEditCommand.h (165137 => 165138)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/CompositeEditCommand.h        2014-03-06 00:03:52 UTC (rev 165137)
+++ trunk/Source/WebCore/editing/CompositeEditCommand.h        2014-03-06 00:05:55 UTC (rev 165138)
</span><span class="lines">@@ -160,7 +160,7 @@
</span><span class="cx">     void moveParagraph(const VisiblePosition&amp;, const VisiblePosition&amp;, const VisiblePosition&amp;, bool preserveSelection = false, bool preserveStyle = true);
</span><span class="cx">     void moveParagraphs(const VisiblePosition&amp;, const VisiblePosition&amp;, const VisiblePosition&amp;, bool preserveSelection = false, bool preserveStyle = true);
</span><span class="cx">     void moveParagraphWithClones(const VisiblePosition&amp; startOfParagraphToMove, const VisiblePosition&amp; endOfParagraphToMove, Element* blockElement, Node* outerNode);
</span><del>-    void cloneParagraphUnderNewElement(Position&amp; start, Position&amp; end, Node* outerNode, Element* blockElement);
</del><ins>+    void cloneParagraphUnderNewElement(const Position&amp; start, const Position&amp; end, Node* outerNode, Element* blockElement);
</ins><span class="cx">     void cleanupAfterDeletion(VisiblePosition destination = VisiblePosition());
</span><span class="cx">     
</span><span class="cx">     bool breakOutOfEmptyListItem();
</span></span></pre>
</div>
</div>

</body>
</html>