Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(734)

Unified Diff: Source/core/dom/Element.cpp

Issue 398653003: Fix possible crash in Element::normalizeAttributes() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix fast/dom/normalize-attributes-mutation-event-crash.html failure Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/fast/dom/Element/normalize-crash2-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/Element.cpp
diff --git a/Source/core/dom/Element.cpp b/Source/core/dom/Element.cpp
index d7b4a1239835cec7ba4f6b992c0368b535cda941..726da802089e1035f4304140596422fe4b8e292f 100644
--- a/Source/core/dom/Element.cpp
+++ b/Source/core/dom/Element.cpp
@@ -2533,14 +2533,15 @@ void Element::normalizeAttributes()
{
if (!hasAttributes())
return;
- // attributeCount() cannot be cached before the loop because the attributes
- // list is altered while iterating.
- AttributeCollection attributes = this->attributes();
- AttributeCollection::const_iterator end = attributes.end();
- for (AttributeCollection::const_iterator it = attributes.begin(); it < end; ++it) {
- if (RefPtrWillBeRawPtr<Attr> attr = attrIfExists(it->name()))
- attr->normalize();
- }
+ WillBeHeapVector<RefPtrWillBeMember<Attr> >* attrNodes = attrNodeList();
+ if (!attrNodes)
+ return;
+ // Copy the Attr Vector because Node::normalize() can fire synchronous JS
+ // events (e.g. DOMSubtreeModified) and a JS listener could add / remove
+ // attributes while we are iterating.
+ WillBeHeapVector<RefPtrWillBeMember<Attr> > attrNodesCopy(*attrNodes);
+ for (size_t i = 0; i < attrNodesCopy.size(); ++i)
+ attrNodesCopy[i]->normalize();
}
void Element::updatePseudoElement(PseudoId pseudoId, StyleRecalcChange change)
« no previous file with comments | « LayoutTests/fast/dom/Element/normalize-crash2-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698