diff options
author | Sebastian Dröge <sebastian@centricular.com> | 2016-11-25 15:59:44 +0200 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2016-11-25 15:59:44 +0200 |
commit | 31a2f2d5a16d2bb321ed8fcad20fbaaa7b63ae20 (patch) | |
tree | 6e886845bd49b2e1f07b0ad2f59f5b29e4c683ad /gst/mxf/mxftypes.c | |
parent | 73e02f45535c5732028a8b44466384cf711b3e3e (diff) | |
download | gstreamer-plugins-bad-31a2f2d5a16d2bb321ed8fcad20fbaaa7b63ae20.tar.gz |
mxfdemux: Handle zero-sized KLV items better and don't assert on them
Diffstat (limited to 'gst/mxf/mxftypes.c')
-rw-r--r-- | gst/mxf/mxftypes.c | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/gst/mxf/mxftypes.c b/gst/mxf/mxftypes.c index 4063fe041..8355126a5 100644 --- a/gst/mxf/mxftypes.c +++ b/gst/mxf/mxftypes.c @@ -326,11 +326,12 @@ mxf_uuid_array_parse (MXFUUID ** array, guint32 * count, const guint8 * data, g_return_val_if_fail (array != NULL, FALSE); g_return_val_if_fail (count != NULL, FALSE); - g_return_val_if_fail (data != NULL, FALSE); if (size < 8) return FALSE; + g_return_val_if_fail (data != NULL, FALSE); + element_count = GST_READ_UINT32_BE (data); data += 4; size -= 4; @@ -492,7 +493,6 @@ mxf_umid_init (MXFUMID * umid) gboolean mxf_timestamp_parse (MXFTimestamp * timestamp, const guint8 * data, guint size) { - g_return_val_if_fail (data != NULL, FALSE); g_return_val_if_fail (timestamp != NULL, FALSE); memset (timestamp, 0, sizeof (MXFTimestamp)); @@ -500,6 +500,8 @@ mxf_timestamp_parse (MXFTimestamp * timestamp, const guint8 * data, guint size) if (size < 8) return FALSE; + g_return_val_if_fail (data != NULL, FALSE); + timestamp->year = GST_READ_UINT16_BE (data); timestamp->month = GST_READ_UINT8 (data + 2); timestamp->day = GST_READ_UINT8 (data + 3); @@ -597,13 +599,14 @@ gboolean mxf_fraction_parse (MXFFraction * fraction, const guint8 * data, guint size) { g_return_val_if_fail (fraction != NULL, FALSE); - g_return_val_if_fail (data != NULL, FALSE); memset (fraction, 0, sizeof (MXFFraction)); if (size < 8) return FALSE; + g_return_val_if_fail (data != NULL, FALSE); + fraction->n = GST_READ_UINT32_BE (data); fraction->d = GST_READ_UINT32_BE (data + 4); @@ -669,13 +672,14 @@ mxf_product_version_parse (MXFProductVersion * product_version, const guint8 * data, guint size) { g_return_val_if_fail (product_version != NULL, FALSE); - g_return_val_if_fail (data != NULL, FALSE); memset (product_version, 0, sizeof (MXFProductVersion)); if (size < 9) return FALSE; + g_return_val_if_fail (data != NULL, FALSE); + product_version->major = GST_READ_UINT16_BE (data); product_version->minor = GST_READ_UINT16_BE (data + 2); product_version->patch = GST_READ_UINT16_BE (data + 4); @@ -769,8 +773,10 @@ mxf_partition_pack_parse (const MXFUL * ul, MXFPartitionPack * pack, gchar str[48]; #endif + if (size < 84) + return FALSE; + g_return_val_if_fail (data != NULL, FALSE); - g_return_val_if_fail (size >= 84, FALSE); memset (pack, 0, sizeof (MXFPartitionPack)); @@ -991,12 +997,13 @@ mxf_random_index_pack_parse (const MXFUL * ul, const guint8 * data, guint size, guint len, i; MXFRandomIndexPackEntry entry; - g_return_val_if_fail (data != NULL, FALSE); g_return_val_if_fail (array != NULL, FALSE); if (size < 4) return FALSE; + g_return_val_if_fail (data != NULL, FALSE); + if ((size - 4) % 12 != 0) return FALSE; @@ -1072,13 +1079,14 @@ mxf_index_table_segment_parse (const MXFUL * ul, const guint8 *tag_data; g_return_val_if_fail (ul != NULL, FALSE); - g_return_val_if_fail (data != NULL, FALSE); memset (segment, 0, sizeof (MXFIndexTableSegment)); if (size < 70) return FALSE; + g_return_val_if_fail (data != NULL, FALSE); + GST_DEBUG ("Parsing index table segment:"); while (mxf_local_tag_parse (data, size, &tag, &tag_size, &tag_data)) { @@ -1436,8 +1444,10 @@ mxf_primer_pack_parse (const MXFUL * ul, MXFPrimerPack * pack, guint i; guint32 n; + if (size < 8) + return FALSE; + g_return_val_if_fail (data != NULL, FALSE); - g_return_val_if_fail (size >= 8, FALSE); memset (pack, 0, sizeof (MXFPrimerPack)); @@ -1614,11 +1624,11 @@ gboolean mxf_local_tag_parse (const guint8 * data, guint size, guint16 * tag, guint16 * tag_size, const guint8 ** tag_data) { - g_return_val_if_fail (data != NULL, FALSE); - if (size < 4) return FALSE; + g_return_val_if_fail (data != NULL, FALSE); + *tag = GST_READ_UINT16_BE (data); *tag_size = GST_READ_UINT16_BE (data + 2); @@ -1652,7 +1662,7 @@ mxf_local_tag_add_to_hash_table (const MXFPrimerPack * primer, MXFUL *ul; g_return_val_if_fail (primer != NULL, FALSE); - g_return_val_if_fail (tag_data != NULL, FALSE); + g_return_val_if_fail (tag_size == 0 || tag_data != NULL, FALSE); g_return_val_if_fail (hash_table != NULL, FALSE); g_return_val_if_fail (primer->mappings != NULL, FALSE); @@ -1678,7 +1688,7 @@ mxf_local_tag_add_to_hash_table (const MXFPrimerPack * primer, local_tag = g_slice_new0 (MXFLocalTag); memcpy (&local_tag->ul, ul, sizeof (MXFUL)); local_tag->size = tag_size; - local_tag->data = g_memdup (tag_data, tag_size); + local_tag->data = tag_size == 0 ? NULL : g_memdup (tag_data, tag_size); local_tag->g_slice = FALSE; g_hash_table_insert (*hash_table, &local_tag->ul, local_tag); |