[GStreamer] Fix overflow in buffered ranges
authoraboya@igalia.com <aboya@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 10 Sep 2018 14:04:32 +0000 (14:04 +0000)
committeraboya@igalia.com <aboya@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 10 Sep 2018 14:04:32 +0000 (14:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=189419

Reviewed by Philippe Normand.

Scale operations on big numbers (like media timestamps or durations)
should be made with GStreamer utility functions to avoid overflows.

This fixes an assertion when a 24 hour long fragmented MP4 file is
played.

* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::buffered const):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@235848 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp

index a8b573b..dd210ef 100644 (file)
@@ -1,3 +1,19 @@
+2018-09-10  Alicia Boya GarcĂ­a  <aboya@igalia.com>
+
+        [GStreamer] Fix overflow in buffered ranges
+        https://bugs.webkit.org/show_bug.cgi?id=189419
+
+        Reviewed by Philippe Normand.
+
+        Scale operations on big numbers (like media timestamps or durations)
+        should be made with GStreamer utility functions to avoid overflows.
+
+        This fixes an assertion when a 24 hour long fragmented MP4 file is
+        played.
+
+        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
+        (WebCore::MediaPlayerPrivateGStreamer::buffered const):
+
 2018-09-07  Frederic Wang  <fwang@igalia.com>
 
         Refactor filter list checking code
index b6829f2..b900e9e 100644 (file)
@@ -1125,8 +1125,9 @@ std::unique_ptr<PlatformTimeRanges> MediaPlayerPrivateGStreamer::buffered() cons
     for (guint index = 0; index < numBufferingRanges; index++) {
         gint64 rangeStart = 0, rangeStop = 0;
         if (gst_query_parse_nth_buffering_range(query, index, &rangeStart, &rangeStop)) {
-            timeRanges->add(MediaTime(rangeStart * toGstUnsigned64Time(mediaDuration) / GST_FORMAT_PERCENT_MAX, GST_SECOND),
-                MediaTime(rangeStop * toGstUnsigned64Time(mediaDuration) / GST_FORMAT_PERCENT_MAX, GST_SECOND));
+            uint64_t startTime = gst_util_uint64_scale_int_round(toGstUnsigned64Time(mediaDuration), rangeStart, GST_FORMAT_PERCENT_MAX);
+            uint64_t stopTime = gst_util_uint64_scale_int_round(toGstUnsigned64Time(mediaDuration), rangeStop, GST_FORMAT_PERCENT_MAX);
+            timeRanges->add(MediaTime(startTime, GST_SECOND), MediaTime(stopTime, GST_SECOND));
         }
     }