audio-format: Add macro checking for validity of GstAudioFormatInfo
authorPhilippe Normand <philn@igalia.com>
Wed, 27 Jul 2022 08:39:52 +0000 (09:39 +0100)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Mon, 12 Dec 2022 19:39:10 +0000 (19:39 +0000)
`gst_audio_format_info_fill_silence()` not properly checking the validity of its
input may lead it into an infinite loop.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2800>

subprojects/gst-plugins-base/gst-libs/gst/audio/audio-format.c
subprojects/gst-plugins-base/gst-libs/gst/audio/audio-format.h

index 17320d2..b1b8d60 100644 (file)
@@ -486,7 +486,7 @@ gst_audio_format_info_fill_silence (const GstAudioFormatInfo * info,
 {
   guint8 *dptr = dest;
 
-  g_return_if_fail (info != NULL);
+  g_return_if_fail (GST_AUDIO_FORMAT_INFO_IS_VALID_RAW (info));
   g_return_if_fail (dest != NULL);
 
   if (info->flags & GST_AUDIO_FORMAT_FLAG_FLOAT ||
index 15e970f..c7aeef8 100644 (file)
@@ -256,6 +256,18 @@ struct _GstAudioFormatInfo {
 GST_AUDIO_API
 GType gst_audio_format_info_get_type (void);
 
+/**
+ * GST_AUDIO_FORMAT_INFO_IS_VALID_RAW:
+ *
+ * Tests that the given #GstAudioFormatInfo represents a valid un-encoded
+ * format.
+ *
+ * Since: 1.22
+ */
+#define GST_AUDIO_FORMAT_INFO_IS_VALID_RAW(info)                        \
+  (info != NULL && (info)->format > GST_AUDIO_FORMAT_ENCODED &&         \
+   (info)->width > 0 && (info)->depth > 0)
+
 #define GST_AUDIO_FORMAT_INFO_FORMAT(info)           ((info)->format)
 #define GST_AUDIO_FORMAT_INFO_NAME(info)             ((info)->name)
 #define GST_AUDIO_FORMAT_INFO_FLAGS(info)            ((info)->flags)