From 42651f72ff4a35dbff5115e8642c690338cbdbfc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim-Philipp=20M=C3=BCller?= Date: Fri, 4 May 2007 12:37:01 +0000 Subject: [PATCH] libs/gst/controller/: Don't crash if someone tries to set an interpolation mode that is invalid or that isn't support... Original commit message from CVS: * libs/gst/controller/gstcontroller.c: (gst_controlled_property_set_interpolation_mode): * libs/gst/controller/gstinterpolation.c: Don't crash if someone tries to set an interpolation mode that is invalid or that isn't supported yet. Fixes #422295. * tests/check/libs/controller.c: (GST_START_TEST), (gst_controller_suite): Add a test case for the above. --- ChangeLog | 12 ++++++++++++ libs/gst/controller/gstcontroller.c | 6 ++++++ libs/gst/controller/gstinterpolation.c | 2 ++ tests/check/libs/controller.c | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+) diff --git a/ChangeLog b/ChangeLog index cbc222b..74aa06c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2007-05-04 Tim-Philipp Müller + + * libs/gst/controller/gstcontroller.c: + (gst_controlled_property_set_interpolation_mode): + * libs/gst/controller/gstinterpolation.c: + Don't crash if someone tries to set an interpolation mode that + is invalid or that isn't supported yet. Fixes #422295. + + * tests/check/libs/controller.c: (GST_START_TEST), + (gst_controller_suite): + Add a test case for the above. + 2007-05-03 Edward Hervey * libs/gst/base/gstbasetransform.c: (gst_base_transform_chain): diff --git a/libs/gst/controller/gstcontroller.c b/libs/gst/controller/gstcontroller.c index fd78525..ce2e86b 100644 --- a/libs/gst/controller/gstcontroller.c +++ b/libs/gst/controller/gstcontroller.c @@ -95,6 +95,7 @@ extern GList * gst_controlled_property_find_timed_value_node (GstControlledProperty * prop, GstClockTime timestamp); extern GstInterpolateMethod *interpolation_methods[]; +extern guint num_interpolation_methods; /* callbacks */ @@ -181,6 +182,11 @@ gst_controlled_property_set_interpolation_mode (GstControlledProperty * self, { gboolean res = TRUE; + if (mode >= num_interpolation_methods || interpolation_methods[mode] == NULL) { + GST_WARNING ("interpolation mode %d invalid or not implemented yet", mode); + return FALSE; + } + self->interpolation = mode; if (mode != GST_INTERPOLATE_USER) { switch (self->base) { diff --git a/libs/gst/controller/gstinterpolation.c b/libs/gst/controller/gstinterpolation.c index 7237f85..a66fc48 100644 --- a/libs/gst/controller/gstinterpolation.c +++ b/libs/gst/controller/gstinterpolation.c @@ -319,3 +319,5 @@ GstInterpolateMethod *interpolation_methods[] = { NULL, NULL }; + +guint num_interpolation_methods = G_N_ELEMENTS (interpolation_methods); diff --git a/tests/check/libs/controller.c b/tests/check/libs/controller.c index 9b22231..befcc9b 100644 --- a/tests/check/libs/controller.c +++ b/tests/check/libs/controller.c @@ -638,6 +638,38 @@ GST_START_TEST (controller_interpolate_linear) GST_END_TEST; +/* make sure we don't crash when someone sets an unsupported interpolation + * mode */ +GST_START_TEST (controller_interpolate_unimplemented) +{ + GstController *ctrl; + GstElement *elem; + + gst_controller_init (NULL, NULL); + + elem = gst_element_factory_make ("testmonosource", "test_source"); + + /* that property should exist and should be controllable */ + ctrl = gst_controller_new (G_OBJECT (elem), "ulong", NULL); + fail_unless (ctrl != NULL, NULL); + + /* set unsupported interpolation mode */ + gst_controller_set_interpolation_mode (ctrl, "ulong", GST_INTERPOLATE_CUBIC); + + /* set another unsupported interpolation mode */ + gst_controller_set_interpolation_mode (ctrl, "ulong", + GST_INTERPOLATE_QUADRATIC); + + /* set completely bogus interpolation mode */ + gst_controller_set_interpolation_mode (ctrl, "ulong", + (GstInterpolateMode) 93871); + + g_object_unref (ctrl); + gst_object_unref (elem); +} + +GST_END_TEST; + /* test _unset() */ GST_START_TEST (controller_unset) { @@ -958,6 +990,7 @@ gst_controller_suite (void) tcase_add_test (tc, controller_interpolate_none); tcase_add_test (tc, controller_interpolate_trigger); tcase_add_test (tc, controller_interpolate_linear); + tcase_add_test (tc, controller_interpolate_unimplemented); tcase_add_test (tc, controller_unset); tcase_add_test (tc, controller_unset_all); tcase_add_test (tc, controller_live); -- 2.7.4