summaryrefslogtreecommitdiff
path: root/gst
diff options
context:
space:
mode:
authorJan Schmidt <jan@centricular.com>2015-04-03 02:08:50 +1100
committerJan Schmidt <jan@centricular.com>2015-04-03 23:07:07 +1100
commitffa5fce0946000fd3ea4eb86a297d7a759e27931 (patch)
tree9f669fcf2e68367baa985d578304191f6e88d13c /gst
parent3d59b5f814aebbd8297f08826722ba5c00dd3c30 (diff)
qtdemux: Guard against 64-bit overflow
For large-file atoms, guard against overflow in the size field, which could make us jump backward in the file and cause infinite loops.
Diffstat (limited to 'gst')
-rw-r--r--gst/isomp4/qtdemux.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/gst/isomp4/qtdemux.c b/gst/isomp4/qtdemux.c
index bf856de1a..d0e391e9d 100644
--- a/gst/isomp4/qtdemux.c
+++ b/gst/isomp4/qtdemux.c
@@ -2369,7 +2369,7 @@ extract_initial_length_and_fourcc (const guint8 * data, guint size,
GST_DEBUG ("atom type %" GST_FOURCC_FORMAT, GST_FOURCC_ARGS (fourcc));
if (length == 0) {
- length = G_MAXUINT32;
+ length = G_MAXUINT64;
} else if (length == 1 && size >= 16) {
/* this means we have an extended size, which is the 64 bit value of
* the next 8 bytes */
@@ -3240,6 +3240,15 @@ broken_file:
}
}
+static guint64
+add_offset (guint64 offset, guint64 advance)
+{
+ /* Avoid 64-bit overflow by clamping */
+ if (offset > G_MAXUINT64 - advance)
+ return G_MAXUINT64;
+ return offset + advance;
+}
+
static GstFlowReturn
gst_qtdemux_loop_state_header (GstQTDemux * qtdemux)
{
@@ -3293,7 +3302,7 @@ gst_qtdemux_loop_state_header (GstQTDemux * qtdemux)
GST_LOG_OBJECT (qtdemux,
"skipping atom '%" GST_FOURCC_FORMAT "' at %" G_GUINT64_FORMAT,
GST_FOURCC_ARGS (fourcc), cur_offset);
- qtdemux->offset += length;
+ qtdemux->offset = add_offset (qtdemux->offset, length);
break;
}
case FOURCC_moov:
@@ -3302,7 +3311,7 @@ gst_qtdemux_loop_state_header (GstQTDemux * qtdemux)
if (qtdemux->got_moov) {
GST_DEBUG_OBJECT (qtdemux, "Skipping moov atom as we have one already");
- qtdemux->offset += length;
+ qtdemux->offset = add_offset (qtdemux->offset, length);
goto beach;
}