Backport of: From 5d505d108800cef210f67dcfed2801ba36beac2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 20 Jan 2017 12:41:16 +0200 Subject: [PATCH] riff-media: Don't divide block align by zero channels https://bugzilla.gnome.org/show_bug.cgi?id=777525 --- gst-libs/gst/riff/riff-media.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) Index: gst-plugins-base0.10-0.10.36/gst-libs/gst/riff/riff-media.c =================================================================== --- gst-plugins-base0.10-0.10.36.orig/gst-libs/gst/riff/riff-media.c 2017-03-23 13:13:29.708612812 -0400 +++ gst-plugins-base0.10-0.10.36/gst-libs/gst/riff/riff-media.c 2017-03-23 13:30:34.820954947 -0400 @@ -1196,23 +1196,29 @@ if (strf != NULL) { gint ba = strf->blockalign; gint ch = strf->channels; - gint wd = ba * 8 / ch; - caps = gst_caps_new_simple ("audio/x-raw-float", - "endianness", G_TYPE_INT, G_LITTLE_ENDIAN, - "channels", G_TYPE_INT, ch, "width", G_TYPE_INT, wd, NULL); + if (ba > 0 && ch > 0 && (ba == (64 / 8) * ch || ba == (32 / 8) * ch)) { + gint wd = ba * 8 / ch; - /* Add default channel layout. In theory this should be done - * for 1 and 2 channels too but apparently breaks too many - * things currently. Also we know no default layout for more than - * 8 channels. */ - if (ch > 2) { - if (ch > 8) - GST_WARNING ("don't know default layout for %d channels", ch); - else if (gst_riff_wave_add_default_channel_layout (caps)) - GST_DEBUG ("using default channel layout for %d channels", ch); - else - GST_WARNING ("failed to add channel layout"); + caps = gst_caps_new_simple ("audio/x-raw-float", + "endianness", G_TYPE_INT, G_LITTLE_ENDIAN, + "channels", G_TYPE_INT, ch, "width", G_TYPE_INT, wd, NULL); + + /* Add default channel layout. In theory this should be done + * for 1 and 2 channels too but apparently breaks too many + * things currently. Also we know no default layout for more than + * 8 channels. */ + if (ch > 2) { + if (ch > 8) + GST_WARNING ("don't know default layout for %d channels", ch); + else if (gst_riff_wave_add_default_channel_layout (caps)) + GST_DEBUG ("using default channel layout for %d channels", ch); + else + GST_WARNING ("failed to add channel layout"); + } + } else { + GST_WARNING ("invalid block align %d or channel count %d", ba, ch); + return NULL; } } else { /* FIXME: this is pretty useless - we need fixed caps */