[0.11] gst-plugins-bad: mpegpsdemux: handle corner-case of short read in pull_buffer better

Sebastian Dröge slomo at kemper.freedesktop.org
Wed Jan 25 04:23:57 PST 2012


Module: gst-plugins-bad
Branch: 0.11
Commit: 27354f065df047ca0d08a49daf15949d64426f3d
URL:    http://cgit.freedesktop.org/gstreamer/gst-plugins-bad/commit/?id=27354f065df047ca0d08a49daf15949d64426f3d

Author: Tim-Philipp Müller <tim.muller at collabora.co.uk>
Date:   Tue Jan 10 00:22:38 2012 +0000

mpegpsdemux: handle corner-case of short read in pull_buffer better

It's extremely unlikely, but there are corner cases where a short
read might happen, so handle that, just in case.

---

 gst/mpegdemux/gstmpegdemux.c |   20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/gst/mpegdemux/gstmpegdemux.c b/gst/mpegdemux/gstmpegdemux.c
index 55a567e..7d5b139 100644
--- a/gst/mpegdemux/gstmpegdemux.c
+++ b/gst/mpegdemux/gstmpegdemux.c
@@ -2387,7 +2387,7 @@ gst_flups_demux_scan_forward_ts (GstFluPSDemux * demux, guint64 * pos,
   guint scan_sz = (mode == SCAN_SCR ? SCAN_SCR_SZ : SCAN_PTS_SZ);
   guint cursor, to_read = BLOCK_SZ;
   guint8 *data;
-  guint end_scan;
+  guint end_scan, data_size;
 
   do {
     if (offset + scan_sz > demux->sink_segment.stop)
@@ -2401,8 +2401,14 @@ gst_flups_demux_scan_forward_ts (GstFluPSDemux * demux, guint64 * pos,
     if (G_UNLIKELY (ret != GST_FLOW_OK))
       return FALSE;
 
+    /* may get a short buffer at the end of the file */
+    data_size = GST_BUFFER_SIZE (buffer);
+    if (G_UNLIKELY (data_size <= scan_sz))
+      return FALSE;
+
     data = GST_BUFFER_DATA (buffer);
-    end_scan = GST_BUFFER_SIZE (buffer) - scan_sz;
+    end_scan = data_size - scan_sz;
+
     /* scan the block */
     for (cursor = 0; !found && cursor <= end_scan; cursor++) {
       found = gst_flups_demux_scan_ts (demux, data++, mode, &ts);
@@ -2433,7 +2439,7 @@ gst_flups_demux_scan_backward_ts (GstFluPSDemux * demux, guint64 * pos,
   guint64 ts = 0;
   guint scan_sz = (mode == SCAN_SCR ? SCAN_SCR_SZ : SCAN_PTS_SZ);
   guint cursor, to_read = BLOCK_SZ;
-  guint start_scan;
+  guint start_scan, data_size;
   guint8 *data;
 
   do {
@@ -2451,8 +2457,14 @@ gst_flups_demux_scan_backward_ts (GstFluPSDemux * demux, guint64 * pos,
     if (G_UNLIKELY (ret != GST_FLOW_OK))
       return FALSE;
 
-    start_scan = GST_BUFFER_SIZE (buffer) - scan_sz;
+    /* may get a short buffer at the end of the file */
+    data_size = GST_BUFFER_SIZE (buffer);
+    if (G_UNLIKELY (data_size <= scan_sz))
+      return FALSE;
+
+    start_scan = data_size - scan_sz;
     data = GST_BUFFER_DATA (buffer) + start_scan;
+
     /* scan the block */
     for (cursor = (start_scan + 1); !found && cursor > 0; cursor--) {
       found = gst_flups_demux_scan_ts (demux, data--, mode, &ts);



More information about the gstreamer-commits mailing list