Title: [151600] trunk
- Revision
- 151600
- Author
- [email protected]
- Date
- 2013-06-14 10:18:59 -0700 (Fri, 14 Jun 2013)
Log Message
Potential use-after-free with an event fired at a HTMLMediaElement which is currently being deleted
https://bugs.webkit.org/show_bug.cgi?id=117466
Reviewed by Oliver Hunt.
Merge https://chromium.googlesource.com/chromium/blink/+/f4200a0093b3d9376f703961615359ec7fb712b4
If an event is created using as target an HTMLMediaElement which is
currently being deleted it becomes a heap-use-after free situation.
The GenericEventQueue instance is already owned by the HTMLMediaElement,
and there already is an underlying mechanism to set the target of the
event to NULL, if their target is owner of the queue.
In order to avoid creating this reference in the first place, we enqueue
the event with a NULL target to defer the refcount increment until the
timer for dispatching the event happens (which won't happen at all if
garbage collection is already destroying the objects).
Source/WebCore:
Test: media/track/media-element-enqueue-event-crash.html
* dom/GenericEventQueue.cpp:
(WebCore::GenericEventQueue::enqueueEvent): Don't ASSERT if the event has no target.
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::~HTMLMediaElement): Close the event queue so it won't try to
dispatch any pending events.
(WebCore::HTMLMediaElement::scheduleEvent): Don't set the event target, it will happen just
prior to event dispatch.
(WebCore::HTMLMediaElement::stop): Close the event queue.
LayoutTests:
* media/track/media-element-enqueue-event-crash-expected.txt: Added.
* media/track/media-element-enqueue-event-crash.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (151599 => 151600)
--- trunk/LayoutTests/ChangeLog 2013-06-14 17:09:49 UTC (rev 151599)
+++ trunk/LayoutTests/ChangeLog 2013-06-14 17:18:59 UTC (rev 151600)
@@ -1,3 +1,27 @@
+2013-06-14 Eric Carlson <[email protected]>
+
+ Potential use-after-free with an event fired at a HTMLMediaElement which is currently being deleted
+ https://bugs.webkit.org/show_bug.cgi?id=117466
+
+ Reviewed by Oliver Hunt.
+
+ Merge https://chromium.googlesource.com/chromium/blink/+/f4200a0093b3d9376f703961615359ec7fb712b4
+
+ If an event is created using as target an HTMLMediaElement which is
+ currently being deleted it becomes a heap-use-after free situation.
+
+ The GenericEventQueue instance is already owned by the HTMLMediaElement,
+ and there already is an underlying mechanism to set the target of the
+ event to NULL, if their target is owner of the queue.
+
+ In order to avoid creating this reference in the first place, we enqueue
+ the event with a NULL target to defer the refcount increment until the
+ timer for dispatching the event happens (which won't happen at all if
+ garbage collection is already destroying the objects).
+
+ * media/track/media-element-enqueue-event-crash-expected.txt: Added.
+ * media/track/media-element-enqueue-event-crash.html: Added.
+
2013-06-14 Gabor Abraham <[email protected]>
[Qt] Unreviewed gardening. Generate new baseline to some tests and bot greening.
Added: trunk/LayoutTests/media/track/media-element-enqueue-event-crash-expected.txt (0 => 151600)
--- trunk/LayoutTests/media/track/media-element-enqueue-event-crash-expected.txt (rev 0)
+++ trunk/LayoutTests/media/track/media-element-enqueue-event-crash-expected.txt 2013-06-14 17:18:59 UTC (rev 151600)
@@ -0,0 +1,4 @@
+Tests that appending events for dispatching doesn't crash
+
+** No crash. Pass **
+
Added: trunk/LayoutTests/media/track/media-element-enqueue-event-crash.html (0 => 151600)
--- trunk/LayoutTests/media/track/media-element-enqueue-event-crash.html (rev 0)
+++ trunk/LayoutTests/media/track/media-element-enqueue-event-crash.html 2013-06-14 17:18:59 UTC (rev 151600)
@@ -0,0 +1,59 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <script src=""
+ <script src=""
+
+ <script>
+ if (window.testRunner)
+ {
+ testRunner.dumpAsText();
+ testRunner.waitUntilDone();
+ }
+
+ function startTest()
+ {
+ if (localStorage.testRuns)
+ localStorage.testRuns = Number(localStorage.testRuns) + 1;
+ else {
+ localStorage.testRuns = 1;
+ localStorage.totalRuns = 5;
+ }
+
+ document.getElementsByTagName('track')[0].track.mode = 'showing';
+ setTimeout(CFcrash, 100);
+ }
+
+ function forceGC() {
+ gc();
+
+ // End the test only if it ran at least totalRuns.
+ if (window.testRunner && localStorage.testRuns == localStorage.totalRuns) {
+ consoleWrite("** No crash. Pass **");
+ testRunner.notifyDone();
+ } else
+ window.location.reload();
+ }
+
+ function CFcrash()
+ {
+ document1 = document.implementation.createDocument("", null);
+ document1.appendChild(videoElement);
+ delete document1;
+
+ setTimeout(forceGC, 0);
+ }
+
+ document.addEventListener("DOMContentLoaded", startTest, false);
+ </script>
+ </head>
+
+ <body>
+ <p>Tests that appending events for dispatching doesn't crash</p>
+ <video autoplay id="videoElement">
+ <source src=""
+ <source src=""
+ <track src="" default>
+ </video>
+ </body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (151599 => 151600)
--- trunk/Source/WebCore/ChangeLog 2013-06-14 17:09:49 UTC (rev 151599)
+++ trunk/Source/WebCore/ChangeLog 2013-06-14 17:18:59 UTC (rev 151600)
@@ -1,3 +1,36 @@
+2013-06-14 Eric Carlson <[email protected]>
+
+ Potential use-after-free with an event fired at a HTMLMediaElement which is currently being deleted
+ https://bugs.webkit.org/show_bug.cgi?id=117466
+
+ Reviewed by Oliver Hunt.
+
+ Merge https://chromium.googlesource.com/chromium/blink/+/f4200a0093b3d9376f703961615359ec7fb712b4
+
+ If an event is created using as target an HTMLMediaElement which is
+ currently being deleted it becomes a heap-use-after free situation.
+
+ The GenericEventQueue instance is already owned by the HTMLMediaElement,
+ and there already is an underlying mechanism to set the target of the
+ event to NULL, if their target is owner of the queue.
+
+ In order to avoid creating this reference in the first place, we enqueue
+ the event with a NULL target to defer the refcount increment until the
+ timer for dispatching the event happens (which won't happen at all if
+ garbage collection is already destroying the objects).
+
+ Test: media/track/media-element-enqueue-event-crash.html
+
+ * dom/GenericEventQueue.cpp:
+ (WebCore::GenericEventQueue::enqueueEvent): Don't ASSERT if the event has no target.
+
+ * html/HTMLMediaElement.cpp:
+ (WebCore::HTMLMediaElement::~HTMLMediaElement): Close the event queue so it won't try to
+ dispatch any pending events.
+ (WebCore::HTMLMediaElement::scheduleEvent): Don't set the event target, it will happen just
+ prior to event dispatch.
+ (WebCore::HTMLMediaElement::stop): Close the event queue.
+
2013-06-14 Dean Jackson <[email protected]>
Clicking on snapshotting plug-ins does not restart them
Modified: trunk/Source/WebCore/dom/GenericEventQueue.cpp (151599 => 151600)
--- trunk/Source/WebCore/dom/GenericEventQueue.cpp 2013-06-14 17:09:49 UTC (rev 151599)
+++ trunk/Source/WebCore/dom/GenericEventQueue.cpp 2013-06-14 17:18:59 UTC (rev 151600)
@@ -52,7 +52,6 @@
if (m_isClosed)
return false;
- ASSERT(event->target());
if (event->target() == m_owner)
event->setTarget(0);
Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (151599 => 151600)
--- trunk/Source/WebCore/html/HTMLMediaElement.cpp 2013-06-14 17:09:49 UTC (rev 151599)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp 2013-06-14 17:18:59 UTC (rev 151600)
@@ -346,6 +346,8 @@
{
LOG(Media, "HTMLMediaElement::~HTMLMediaElement");
+ m_asyncEventQueue->close();
+
if (m_isWaitingUntilMediaCanStart)
document()->removeMediaCanStartListener(this);
setShouldDelayLoadEvent(false);
@@ -681,7 +683,9 @@
LOG(Media, "HTMLMediaElement::scheduleEvent - scheduling '%s'", eventName.string().ascii().data());
#endif
RefPtr<Event> event = Event::create(eventName, false, true);
- event->setTarget(this);
+
+ // Don't set the event target, the event queue will set it in GenericEventQueue::timerFired and setting it here
+ // will trigger an ASSERT if this element has been marked for deletion.
m_asyncEventQueue->enqueueEvent(event.release());
}
@@ -4155,6 +4159,8 @@
stopPeriodicTimers();
cancelPendingEventsAndCallbacks();
+
+ m_asyncEventQueue->close();
}
void HTMLMediaElement::suspend(ReasonForSuspension why)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes