summaryrefslogtreecommitdiff
path: root/gst
diff options
context:
space:
mode:
authorTim-Philipp Müller <tim.muller@collabora.co.uk>2012-01-10 00:22:38 +0000
committerTim-Philipp Müller <tim.muller@collabora.co.uk>2012-01-19 15:56:12 +0000
commit27354f065df047ca0d08a49daf15949d64426f3d (patch)
tree64c675f77fd1c1fc134818c6750d4d51560d1c69 /gst
parentc6edc0463d964c89be5b0b51ae6b1a903cdc4b6a (diff)
downloadgstreamer-plugins-bad-27354f065df047ca0d08a49daf15949d64426f3d.tar.gz
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.
Diffstat (limited to 'gst')
-rw-r--r--gst/mpegdemux/gstmpegdemux.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/gst/mpegdemux/gstmpegdemux.c b/gst/mpegdemux/gstmpegdemux.c
index 55a567eb0..7d5b13905 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);