summaryrefslogtreecommitdiffstats
path: root/ext/annodex/gstcmmlutils.c
diff options
context:
space:
mode:
authorAlessandro Decina <alessandro@nnva.org>2006-08-25 09:42:43 +0000
committerWim Taymans <wim.taymans@gmail.com>2006-08-25 09:42:43 +0000
commit2f4517a70b9ef85bd18d232b6596848f8a285f7c (patch)
tree2f9e807b42c9ab22328452db45a03fe0930dc91d /ext/annodex/gstcmmlutils.c
parent2019f527f701018622083cdbba4b12b4f53875de (diff)
ext/annodex/gstannodex.c: Do some extra sanity checks.
Original commit message from CVS: Patch by: Alessandro Decina <alessandro at nnva dot org> * ext/annodex/gstannodex.c: (gst_annodex_granule_to_time): Do some extra sanity checks. Fixes #350340. * ext/annodex/gstcmmlenc.c: (gst_cmml_enc_change_state), (gst_cmml_enc_parse_tag_head), (gst_cmml_enc_parse_tag_clip), (gst_cmml_enc_push_clip), (gst_cmml_enc_push): Check if clip->start_time is valid before adding the clip to the track list. Reset enc->preamble going from PAUSED to READY. Don't use GST_FLOW_UNEXPECTED for wrong usage of the element, it is only used for EOS. Only post an error message if we were the one that created the fatal GstFlowReturn value. * ext/annodex/gstcmmlutils.c: (gst_cmml_clock_time_from_npt), (gst_cmml_clock_time_to_granule), (gst_cmml_track_list_has_clip): Parse the seconds field of the npt-sec time format using %llu rather than %d and check that the value scaled by GST_SECOND doesn't overflow. Use guint64(s) to represent the keyindex and keyoffset fields of a granulepos. Lookup a clip's track with clip->track rather than clip->id which makes no sense. Identify a clip by its track and start time and not its xml id. do some more input checking and make sure we don't do undefined shifts. * tests/check/elements/cmmldec.c: (setup_cmmldec), (teardown_cmmldec), (check_output_buffer_is_equal), (push_data), (cmml_tag_message_pop), (check_headers), (push_clip_full), (push_clip), (push_empty_clip), (check_output_clip), (GST_START_TEST), (cmmldec_suite): * tests/check/elements/cmmlenc.c: (setup_cmmlenc), (teardown_cmmlenc), (check_output_buffer_is_equal), (push_data), (check_headers), (push_clip), (check_clip_times), (check_clip), (check_empty_clip), (GST_START_TEST), (cmmlenc_suite): Added some more checks.
Diffstat (limited to 'ext/annodex/gstcmmlutils.c')
-rw-r--r--ext/annodex/gstcmmlutils.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/ext/annodex/gstcmmlutils.c b/ext/annodex/gstcmmlutils.c
index a9e561f8..48f7fb05 100644
--- a/ext/annodex/gstcmmlutils.c
+++ b/ext/annodex/gstcmmlutils.c
@@ -58,15 +58,17 @@ gst_cmml_clock_time_from_npt (const gchar * time)
seconds_t = seconds * GST_SECOND;
} else {
+ guint64 u64seconds;
+
/* parse npt-sec */
hours_t = 0;
minutes = 0;
- fields = sscanf (time, "%d.%d", &seconds, &mseconds);
+ fields = sscanf (time, "%llu.%d", &u64seconds, &mseconds);
if (seconds < 0)
goto bad_input;
- seconds_t = gst_util_uint64_scale (seconds, GST_SECOND, 1);
- if (seconds == G_MAXUINT64)
+ seconds_t = gst_util_uint64_scale_int (u64seconds, GST_SECOND, 1);
+ if (seconds_t == G_MAXUINT64)
goto overflow;
}
@@ -177,9 +179,13 @@ gst_cmml_clock_time_to_granule (GstClockTime prev_time,
GstClockTime current_time, gint64 granulerate_n, gint64 granulerate_d,
guint8 granuleshift)
{
- gint64 keyindex, keyoffset, granulepos;
+ guint64 keyindex, keyoffset, granulepos, maxoffset;
gint64 granulerate;
+ g_return_val_if_fail (granulerate_d != 0, -1);
+ g_return_val_if_fail (granuleshift > 0, -1);
+ g_return_val_if_fail (granuleshift <= 64, -1);
+
if (prev_time == GST_CLOCK_TIME_NONE)
prev_time = 0;
@@ -191,14 +197,23 @@ gst_cmml_clock_time_to_granule (GstClockTime prev_time,
granulerate_d, granulerate_n);
prev_time = prev_time / granulerate;
- if (prev_time > (((guint64) 1 << (64 - granuleshift)) - 1))
+
+ /* granuleshift == 64 should be a << 0 shift, which is defined */
+ maxoffset = ((guint64) 1 << (64 - granuleshift)) - 1;
+ if (prev_time > maxoffset)
/* we need more than 64 - granuleshift bits to encode prev_time */
goto overflow;
keyindex = prev_time << granuleshift;
keyoffset = (current_time / granulerate) - prev_time;
- if (keyoffset > ((guint64) 1 << granuleshift) - 1)
+ /* make sure we don't shift to the limits of the types as this is undefined. */
+ if (granuleshift == 64)
+ maxoffset = G_MAXUINT64;
+ else
+ maxoffset = ((guint64) 1 << granuleshift) - 1;
+
+ if (keyoffset > maxoffset)
/* we need more than granuleshift bits to encode prev_time - current_time */
goto overflow;
@@ -301,16 +316,13 @@ gst_cmml_track_list_has_clip (GHashTable * tracks, GstCmmlTagClip * clip)
GstCmmlTrack *track;
GList *walk;
GstCmmlTagClip *tmp;
- gchar *clip_id = (gchar *) clip->id;
gboolean res = FALSE;
- g_return_val_if_fail (clip_id != NULL, FALSE);
-
- track = g_hash_table_lookup (tracks, clip_id);
+ track = g_hash_table_lookup (tracks, (gchar *) clip->track);
if (track) {
for (walk = track->clips; walk; walk = g_list_next (walk)) {
tmp = GST_CMML_TAG_CLIP (walk->data);
- if (!strcmp ((gchar *) tmp->id, clip_id)) {
+ if (tmp->start_time == clip->start_time) {
res = TRUE;
break;
}