From 44e4de43dafc550a01c7ba677bd398e135dc550c Mon Sep 17 00:00:00 2001 From: Stian Selnes Date: Wed, 28 Feb 2018 15:46:51 +0100 Subject: [PATCH] vpxdec: Check that output width and height != 0 For VP8 it's possible to signal width or height to be 0, but it does not make sense to do so. For VP9 it's impossible. Hence, we most likely have a corrupt stream. Trying to negotiate caps downstream with either width or height as 0 will fail with something like gst_video_decoder_negotiate_default: assertion 'GST_VIDEO_INFO_WIDTH (&state->info) != 0' failed Part-of: --- ext/vpx/gstvpxdec.c | 8 ++++++++ tests/check/elements/vp8dec.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/ext/vpx/gstvpxdec.c b/ext/vpx/gstvpxdec.c index 3eafb7f..e860715 100644 --- a/ext/vpx/gstvpxdec.c +++ b/ext/vpx/gstvpxdec.c @@ -586,6 +586,14 @@ gst_vpx_dec_open_codec (GstVPXDec * dec, GstVideoCodecFrame * frame) GST_WARNING_OBJECT (dec, "No keyframe, skipping"); return GST_FLOW_CUSTOM_SUCCESS_1; } + if (stream_info.w == 0 || stream_info.h == 0) { + /* For VP8 it's possible to signal width or height to be 0, but it does + * not make sense to do so. For VP9 it's impossible. Hence, we most likely + * have a corrupt stream if width or height is 0. */ + GST_INFO_OBJECT (dec, "Invalid resolution %d x %d", stream_info.w, + stream_info.h); + return GST_FLOW_CUSTOM_SUCCESS_1; + } gst_vpx_dec_set_stream_info (dec, &stream_info); gst_vpx_dec_set_default_format (dec, GST_VIDEO_FORMAT_I420, stream_info.w, diff --git a/tests/check/elements/vp8dec.c b/tests/check/elements/vp8dec.c index 0ebd70a..4ff92c7 100644 --- a/tests/check/elements/vp8dec.c +++ b/tests/check/elements/vp8dec.c @@ -19,6 +19,8 @@ */ #include +#include +#include static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, @@ -248,6 +250,38 @@ GST_START_TEST (test_decode_caps_change) GST_END_TEST; +GST_START_TEST (test_decode_invalid_resolution) +{ + GstHarness *h; + + guint8 invalid_width[] = { + 0x50, 0x48, 0x00, 0x9d, 0x01, 0x2a, 0x00, 0x00, 0x11, 0x44, 0x39, 0x63, + }; + guint8 invalid_height[] = { + 0x50, 0x48, 0x00, 0x9d, 0x01, 0x2a, 0x11, 0x44, 0x00, 0x00, 0x39, 0x63, + }; + + h = gst_harness_new_parse ("vp8dec"); + gst_harness_set_src_caps_str (h, "video/x-vp8"); + + fail_unless_equals_int (GST_FLOW_OK, + gst_harness_push (h, + gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY, invalid_width, + sizeof (invalid_width), 0, sizeof (invalid_width), NULL, NULL))); + fail_unless (gst_harness_try_pull (h) == NULL); + + fail_unless_equals_int (GST_FLOW_OK, + gst_harness_push (h, + gst_buffer_new_wrapped_full (GST_MEMORY_FLAG_READONLY, invalid_height, + sizeof (invalid_height), 0, sizeof (invalid_height), NULL, + NULL))); + fail_unless (gst_harness_try_pull (h) == NULL); + + gst_harness_teardown (h); +} + +GST_END_TEST; + static Suite * vp8dec_suite (void) @@ -259,6 +293,7 @@ vp8dec_suite (void) tcase_add_test (tc_chain, test_decode_simple); tcase_add_test (tc_chain, test_decode_caps_change); + tcase_add_test (tc_chain, test_decode_invalid_resolution); return s; } -- 2.7.4