mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 06:54:49 +00:00
always check file length before making decisions based on it
Original commit message from CVS: always check file length before making decisions based on it
This commit is contained in:
parent
284a8c25e7
commit
6402b4730b
2 changed files with 82 additions and 22 deletions
|
@ -128,6 +128,7 @@ static void gst_filesrc_set_property (GObject *object, guint prop_id,
|
||||||
static void gst_filesrc_get_property (GObject *object, guint prop_id,
|
static void gst_filesrc_get_property (GObject *object, guint prop_id,
|
||||||
GValue *value, GParamSpec *pspec);
|
GValue *value, GParamSpec *pspec);
|
||||||
|
|
||||||
|
static gboolean gst_filesrc_check_filesize (GstFileSrc *src);
|
||||||
static GstData * gst_filesrc_get (GstPad *pad);
|
static GstData * gst_filesrc_get (GstPad *pad);
|
||||||
static gboolean gst_filesrc_srcpad_event (GstPad *pad, GstEvent *event);
|
static gboolean gst_filesrc_srcpad_event (GstPad *pad, GstEvent *event);
|
||||||
static gboolean gst_filesrc_srcpad_query (GstPad *pad, GstQueryType type,
|
static gboolean gst_filesrc_srcpad_query (GstPad *pad, GstQueryType type,
|
||||||
|
@ -506,8 +507,10 @@ gst_filesrc_get_mmap (GstFileSrc *src)
|
||||||
|
|
||||||
/* check to see if we're going to overflow the end of the file */
|
/* check to see if we're going to overflow the end of the file */
|
||||||
if (readend > src->filelen) {
|
if (readend > src->filelen) {
|
||||||
readsize = src->filelen - src->curoffset;
|
if (!gst_filesrc_check_filesize (src) || readend > src->filelen) {
|
||||||
readend = src->curoffset + readsize;
|
readsize = src->filelen - src->curoffset;
|
||||||
|
readend = src->curoffset + readsize;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_LOG ("attempting to read %08lx, %08lx, %08lx, %08lx",
|
GST_LOG ("attempting to read %08lx, %08lx, %08lx, %08lx",
|
||||||
|
@ -626,7 +629,9 @@ gst_filesrc_get_read (GstFileSrc *src)
|
||||||
|
|
||||||
readsize = src->block_size;
|
readsize = src->block_size;
|
||||||
if (src->curoffset + readsize > src->filelen) {
|
if (src->curoffset + readsize > src->filelen) {
|
||||||
readsize = src->filelen - src->curoffset;
|
if (!gst_filesrc_check_filesize (src) || src->curoffset + readsize > src->filelen) {
|
||||||
|
readsize = src->filelen - src->curoffset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = gst_buffer_new_and_alloc (readsize);
|
buf = gst_buffer_new_and_alloc (readsize);
|
||||||
|
@ -675,11 +680,14 @@ gst_filesrc_get (GstPad *pad)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check for EOF */
|
/* check for EOF */
|
||||||
|
g_assert (src->curoffset <= src->filelen);
|
||||||
if (src->curoffset == src->filelen) {
|
if (src->curoffset == src->filelen) {
|
||||||
GST_DEBUG_OBJECT (src, "eos %" G_GINT64_FORMAT" %" G_GINT64_FORMAT,
|
if (!gst_filesrc_check_filesize (src) || src->curoffset >= src->filelen) {
|
||||||
src->curoffset, src->filelen);
|
GST_DEBUG_OBJECT (src, "eos %" G_GINT64_FORMAT" %" G_GINT64_FORMAT,
|
||||||
gst_element_set_eos (GST_ELEMENT (src));
|
src->curoffset, src->filelen);
|
||||||
return GST_DATA (gst_event_new (GST_EVENT_EOS));
|
gst_element_set_eos (GST_ELEMENT (src));
|
||||||
|
return GST_DATA (gst_event_new (GST_EVENT_EOS));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (src->using_mmap){
|
if (src->using_mmap){
|
||||||
|
@ -689,6 +697,22 @@ gst_filesrc_get (GstPad *pad)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* TRUE if the filesize of the file was updated */
|
||||||
|
static gboolean
|
||||||
|
gst_filesrc_check_filesize (GstFileSrc *src)
|
||||||
|
{
|
||||||
|
struct stat stat_results;
|
||||||
|
|
||||||
|
g_return_val_if_fail (GST_FLAG_IS_SET (src ,GST_FILESRC_OPEN), FALSE);
|
||||||
|
|
||||||
|
fstat(src->fd, &stat_results);
|
||||||
|
GST_DEBUG_OBJECT (src, "checked filesize on %s (was %"G_GUINT64_FORMAT", is %"G_GUINT64_FORMAT")",
|
||||||
|
src->filename, src->filelen, (guint64) stat_results.st_size);
|
||||||
|
if (src->filelen == (guint64) stat_results.st_size)
|
||||||
|
return FALSE;
|
||||||
|
src->filelen = stat_results.st_size;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
/* open the file and mmap it, necessary to go to READY state */
|
/* open the file and mmap it, necessary to go to READY state */
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_filesrc_open_file (GstFileSrc *src)
|
gst_filesrc_open_file (GstFileSrc *src)
|
||||||
|
@ -799,6 +823,7 @@ gst_filesrc_srcpad_query (GstPad *pad, GstQueryType type,
|
||||||
if (*format != GST_FORMAT_BYTES) {
|
if (*format != GST_FORMAT_BYTES) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
gst_filesrc_check_filesize (src);
|
||||||
*value = src->filelen;
|
*value = src->filelen;
|
||||||
break;
|
break;
|
||||||
case GST_QUERY_POSITION:
|
case GST_QUERY_POSITION:
|
||||||
|
@ -842,20 +867,25 @@ gst_filesrc_srcpad_event (GstPad *pad, GstEvent *event)
|
||||||
|
|
||||||
switch (GST_EVENT_SEEK_METHOD (event)) {
|
switch (GST_EVENT_SEEK_METHOD (event)) {
|
||||||
case GST_SEEK_METHOD_SET:
|
case GST_SEEK_METHOD_SET:
|
||||||
if (offset > src->filelen)
|
if (offset > src->filelen && (!gst_filesrc_check_filesize (src) || offset > src->filelen)) {
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
src->curoffset = offset;
|
src->curoffset = offset;
|
||||||
GST_DEBUG_OBJECT (src, "seek set pending to %" G_GINT64_FORMAT, src->curoffset);
|
GST_DEBUG_OBJECT (src, "seek set pending to %" G_GINT64_FORMAT, src->curoffset);
|
||||||
break;
|
break;
|
||||||
case GST_SEEK_METHOD_CUR:
|
case GST_SEEK_METHOD_CUR:
|
||||||
if (offset + src->curoffset > src->filelen)
|
if (offset + src->curoffset > src->filelen)
|
||||||
goto error;
|
if (!gst_filesrc_check_filesize (src) || offset + src->curoffset > src->filelen)
|
||||||
|
goto error;
|
||||||
src->curoffset += offset;
|
src->curoffset += offset;
|
||||||
GST_DEBUG_OBJECT (src, "seek cur pending to %" G_GINT64_FORMAT, src->curoffset);
|
GST_DEBUG_OBJECT (src, "seek cur pending to %" G_GINT64_FORMAT, src->curoffset);
|
||||||
break;
|
break;
|
||||||
case GST_SEEK_METHOD_END:
|
case GST_SEEK_METHOD_END:
|
||||||
if (ABS (offset) > src->filelen)
|
if (ABS (offset) > src->filelen) {
|
||||||
|
if (!gst_filesrc_check_filesize (src) || ABS (offset) > src->filelen)
|
||||||
|
goto error;
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
src->curoffset = src->filelen - ABS (offset);
|
src->curoffset = src->filelen - ABS (offset);
|
||||||
GST_DEBUG_OBJECT (src, "seek end pending to %" G_GINT64_FORMAT, src->curoffset);
|
GST_DEBUG_OBJECT (src, "seek end pending to %" G_GINT64_FORMAT, src->curoffset);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -128,6 +128,7 @@ static void gst_filesrc_set_property (GObject *object, guint prop_id,
|
||||||
static void gst_filesrc_get_property (GObject *object, guint prop_id,
|
static void gst_filesrc_get_property (GObject *object, guint prop_id,
|
||||||
GValue *value, GParamSpec *pspec);
|
GValue *value, GParamSpec *pspec);
|
||||||
|
|
||||||
|
static gboolean gst_filesrc_check_filesize (GstFileSrc *src);
|
||||||
static GstData * gst_filesrc_get (GstPad *pad);
|
static GstData * gst_filesrc_get (GstPad *pad);
|
||||||
static gboolean gst_filesrc_srcpad_event (GstPad *pad, GstEvent *event);
|
static gboolean gst_filesrc_srcpad_event (GstPad *pad, GstEvent *event);
|
||||||
static gboolean gst_filesrc_srcpad_query (GstPad *pad, GstQueryType type,
|
static gboolean gst_filesrc_srcpad_query (GstPad *pad, GstQueryType type,
|
||||||
|
@ -506,8 +507,10 @@ gst_filesrc_get_mmap (GstFileSrc *src)
|
||||||
|
|
||||||
/* check to see if we're going to overflow the end of the file */
|
/* check to see if we're going to overflow the end of the file */
|
||||||
if (readend > src->filelen) {
|
if (readend > src->filelen) {
|
||||||
readsize = src->filelen - src->curoffset;
|
if (!gst_filesrc_check_filesize (src) || readend > src->filelen) {
|
||||||
readend = src->curoffset + readsize;
|
readsize = src->filelen - src->curoffset;
|
||||||
|
readend = src->curoffset + readsize;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_LOG ("attempting to read %08lx, %08lx, %08lx, %08lx",
|
GST_LOG ("attempting to read %08lx, %08lx, %08lx, %08lx",
|
||||||
|
@ -626,7 +629,9 @@ gst_filesrc_get_read (GstFileSrc *src)
|
||||||
|
|
||||||
readsize = src->block_size;
|
readsize = src->block_size;
|
||||||
if (src->curoffset + readsize > src->filelen) {
|
if (src->curoffset + readsize > src->filelen) {
|
||||||
readsize = src->filelen - src->curoffset;
|
if (!gst_filesrc_check_filesize (src) || src->curoffset + readsize > src->filelen) {
|
||||||
|
readsize = src->filelen - src->curoffset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = gst_buffer_new_and_alloc (readsize);
|
buf = gst_buffer_new_and_alloc (readsize);
|
||||||
|
@ -675,11 +680,14 @@ gst_filesrc_get (GstPad *pad)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check for EOF */
|
/* check for EOF */
|
||||||
|
g_assert (src->curoffset <= src->filelen);
|
||||||
if (src->curoffset == src->filelen) {
|
if (src->curoffset == src->filelen) {
|
||||||
GST_DEBUG_OBJECT (src, "eos %" G_GINT64_FORMAT" %" G_GINT64_FORMAT,
|
if (!gst_filesrc_check_filesize (src) || src->curoffset >= src->filelen) {
|
||||||
src->curoffset, src->filelen);
|
GST_DEBUG_OBJECT (src, "eos %" G_GINT64_FORMAT" %" G_GINT64_FORMAT,
|
||||||
gst_element_set_eos (GST_ELEMENT (src));
|
src->curoffset, src->filelen);
|
||||||
return GST_DATA (gst_event_new (GST_EVENT_EOS));
|
gst_element_set_eos (GST_ELEMENT (src));
|
||||||
|
return GST_DATA (gst_event_new (GST_EVENT_EOS));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (src->using_mmap){
|
if (src->using_mmap){
|
||||||
|
@ -689,6 +697,22 @@ gst_filesrc_get (GstPad *pad)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* TRUE if the filesize of the file was updated */
|
||||||
|
static gboolean
|
||||||
|
gst_filesrc_check_filesize (GstFileSrc *src)
|
||||||
|
{
|
||||||
|
struct stat stat_results;
|
||||||
|
|
||||||
|
g_return_val_if_fail (GST_FLAG_IS_SET (src ,GST_FILESRC_OPEN), FALSE);
|
||||||
|
|
||||||
|
fstat(src->fd, &stat_results);
|
||||||
|
GST_DEBUG_OBJECT (src, "checked filesize on %s (was %"G_GUINT64_FORMAT", is %"G_GUINT64_FORMAT")",
|
||||||
|
src->filename, src->filelen, (guint64) stat_results.st_size);
|
||||||
|
if (src->filelen == (guint64) stat_results.st_size)
|
||||||
|
return FALSE;
|
||||||
|
src->filelen = stat_results.st_size;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
/* open the file and mmap it, necessary to go to READY state */
|
/* open the file and mmap it, necessary to go to READY state */
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_filesrc_open_file (GstFileSrc *src)
|
gst_filesrc_open_file (GstFileSrc *src)
|
||||||
|
@ -799,6 +823,7 @@ gst_filesrc_srcpad_query (GstPad *pad, GstQueryType type,
|
||||||
if (*format != GST_FORMAT_BYTES) {
|
if (*format != GST_FORMAT_BYTES) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
gst_filesrc_check_filesize (src);
|
||||||
*value = src->filelen;
|
*value = src->filelen;
|
||||||
break;
|
break;
|
||||||
case GST_QUERY_POSITION:
|
case GST_QUERY_POSITION:
|
||||||
|
@ -842,20 +867,25 @@ gst_filesrc_srcpad_event (GstPad *pad, GstEvent *event)
|
||||||
|
|
||||||
switch (GST_EVENT_SEEK_METHOD (event)) {
|
switch (GST_EVENT_SEEK_METHOD (event)) {
|
||||||
case GST_SEEK_METHOD_SET:
|
case GST_SEEK_METHOD_SET:
|
||||||
if (offset > src->filelen)
|
if (offset > src->filelen && (!gst_filesrc_check_filesize (src) || offset > src->filelen)) {
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
src->curoffset = offset;
|
src->curoffset = offset;
|
||||||
GST_DEBUG_OBJECT (src, "seek set pending to %" G_GINT64_FORMAT, src->curoffset);
|
GST_DEBUG_OBJECT (src, "seek set pending to %" G_GINT64_FORMAT, src->curoffset);
|
||||||
break;
|
break;
|
||||||
case GST_SEEK_METHOD_CUR:
|
case GST_SEEK_METHOD_CUR:
|
||||||
if (offset + src->curoffset > src->filelen)
|
if (offset + src->curoffset > src->filelen)
|
||||||
goto error;
|
if (!gst_filesrc_check_filesize (src) || offset + src->curoffset > src->filelen)
|
||||||
|
goto error;
|
||||||
src->curoffset += offset;
|
src->curoffset += offset;
|
||||||
GST_DEBUG_OBJECT (src, "seek cur pending to %" G_GINT64_FORMAT, src->curoffset);
|
GST_DEBUG_OBJECT (src, "seek cur pending to %" G_GINT64_FORMAT, src->curoffset);
|
||||||
break;
|
break;
|
||||||
case GST_SEEK_METHOD_END:
|
case GST_SEEK_METHOD_END:
|
||||||
if (ABS (offset) > src->filelen)
|
if (ABS (offset) > src->filelen) {
|
||||||
|
if (!gst_filesrc_check_filesize (src) || ABS (offset) > src->filelen)
|
||||||
|
goto error;
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
src->curoffset = src->filelen - ABS (offset);
|
src->curoffset = src->filelen - ABS (offset);
|
||||||
GST_DEBUG_OBJECT (src, "seek end pending to %" G_GINT64_FORMAT, src->curoffset);
|
GST_DEBUG_OBJECT (src, "seek end pending to %" G_GINT64_FORMAT, src->curoffset);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue