Bug 1333931 - Handle nullptr TextTrack objects in sorting. r=kinetik
authorRalph Giles <giles@mozilla.com>
Tue, 31 Jan 2017 17:24:17 -0800
changeset 360930 931cbdebf471a80bddf8d834093c5ea6601e87c5
parent 360929 f0a49d9371705f787a732d10dc087017c01c5eeb
child 360931 0ec2488aebbd2f493cb72b99086bf080337189d9
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik
bugs1333931
milestone54.0a1
Bug 1333931 - Handle nullptr TextTrack objects in sorting. r=kinetik Check for nullptr arguments passed to CompareTextTracks. Based on Ben Kelly's analysis this can happen if the cycle collector has cleared a TextTrack pointer while comparision is still happening, perhaps in a queued event task. This change makes nullptr sort to the end, and adds a MOZ_DIAGNOSTIC_ASSERT for trying to get the position of a nullptr track should someone add another call at a later date.
dom/html/TextTrackManager.cpp
--- a/dom/html/TextTrackManager.cpp
+++ b/dom/html/TextTrackManager.cpp
@@ -32,16 +32,17 @@ NS_IMPL_ISUPPORTS(TextTrackManager::Shut
 
 CompareTextTracks::CompareTextTracks(HTMLMediaElement* aMediaElement)
 {
   mMediaElement = aMediaElement;
 }
 
 int32_t
 CompareTextTracks::TrackChildPosition(TextTrack* aTextTrack) const {
+  MOZ_DIAGNOSTIC_ASSERT(aTextTrack);
   HTMLTrackElement* trackElement = aTextTrack->GetTrackElement();
   if (!trackElement) {
     return -1;
   }
   return mMediaElement->IndexOf(trackElement);
 }
 
 bool
@@ -51,16 +52,24 @@ CompareTextTracks::Equals(TextTrack* aOn
   // case of tracks coming from AddTextTrack source we put the newest at the
   // last position, so they won't be equal as well.
   return false;
 }
 
 bool
 CompareTextTracks::LessThan(TextTrack* aOne, TextTrack* aTwo) const
 {
+  // Protect against nullptr TextTrack objects; treat them as
+  // sorting toward the end.
+  if (!aOne) {
+    return false;
+  }
+  if (!aTwo) {
+    return true;
+  }
   TextTrackSource sourceOne = aOne->GetTextTrackSource();
   TextTrackSource sourceTwo = aTwo->GetTextTrackSource();
   if (sourceOne != sourceTwo) {
     return sourceOne == TextTrackSource::Track ||
            (sourceOne == AddTextTrack && sourceTwo == MediaResourceSpecific);
   }
   switch (sourceOne) {
     case Track: {