2017-10-29 07:15:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
* author: Edward Hervey <bilboed@bilboed.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <locale.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <gst/pbutils/pbutils.h>
|
|
|
|
|
2017-12-06 07:41:59 +00:00
|
|
|
#ifndef LOCAL_FUZZ_BUILD
|
2018-11-28 10:09:28 +00:00
|
|
|
GST_PLUGIN_STATIC_DECLARE (coreelements);
|
|
|
|
GST_PLUGIN_STATIC_DECLARE (playback);
|
|
|
|
GST_PLUGIN_STATIC_DECLARE (typefindfunctions);
|
|
|
|
GST_PLUGIN_STATIC_DECLARE (app);
|
|
|
|
GST_PLUGIN_STATIC_DECLARE (ogg);
|
|
|
|
GST_PLUGIN_STATIC_DECLARE (theora);
|
|
|
|
GST_PLUGIN_STATIC_DECLARE (vorbis);
|
2017-12-06 07:41:59 +00:00
|
|
|
#endif
|
2017-10-29 07:15:21 +00:00
|
|
|
|
|
|
|
/* push-based discoverer fuzzing target
|
|
|
|
*
|
|
|
|
* This application can be compiled with libFuzzer to simulate
|
|
|
|
* a push-based discoverer execution.
|
|
|
|
*
|
|
|
|
* To reproduce the failing behaviour, use:
|
|
|
|
* $ gst-discoverer-1.0 pushfile:///...
|
|
|
|
*
|
|
|
|
* The goal is to cover basic usage of demuxers, parsers and
|
|
|
|
* base decoder elements.
|
|
|
|
*
|
|
|
|
* When compiling, only link the required demuxer/parser/decoder
|
|
|
|
* plugins and keep it to a limited range (ex: ogg/theora/vorbis)
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
|
|
|
|
const guint8 *fuzztesting_data;
|
|
|
|
size_t fuzztesting_size;
|
|
|
|
|
|
|
|
static void
|
2018-11-28 10:09:28 +00:00
|
|
|
appsrc_configuration (GstDiscoverer * dc, GstElement * source, gpointer data)
|
2017-10-29 07:15:21 +00:00
|
|
|
{
|
|
|
|
GstBuffer *buf;
|
|
|
|
GstFlowReturn ret;
|
2018-11-28 10:09:28 +00:00
|
|
|
|
2017-10-29 07:15:21 +00:00
|
|
|
/* Create buffer from fuzztesting_data which shouldn't be freed */
|
2018-11-28 10:09:28 +00:00
|
|
|
buf =
|
|
|
|
gst_buffer_new_wrapped_full (0, (gpointer) fuzztesting_data,
|
|
|
|
fuzztesting_size, 0, fuzztesting_size, NULL, NULL);
|
2017-10-29 07:15:21 +00:00
|
|
|
g_object_set (G_OBJECT (source), "size", fuzztesting_size, NULL);
|
2018-11-28 10:09:28 +00:00
|
|
|
g_signal_emit_by_name (G_OBJECT (source), "push-buffer", buf, &ret);
|
2017-10-29 07:15:21 +00:00
|
|
|
gst_buffer_unref (buf);
|
|
|
|
}
|
|
|
|
|
2017-11-01 08:45:36 +00:00
|
|
|
static void
|
2018-11-28 10:09:28 +00:00
|
|
|
custom_logger (const gchar * log_domain,
|
|
|
|
GLogLevelFlags log_level, const gchar * message, gpointer unused_data)
|
2017-11-01 08:45:36 +00:00
|
|
|
{
|
|
|
|
if (log_level & G_LOG_LEVEL_CRITICAL) {
|
|
|
|
g_printerr ("CRITICAL ERROR : %s\n", message);
|
2018-11-28 10:09:28 +00:00
|
|
|
abort ();
|
2017-11-01 08:45:36 +00:00
|
|
|
} else if (log_level & G_LOG_LEVEL_WARNING) {
|
|
|
|
g_printerr ("WARNING : %s\n", message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-28 10:09:28 +00:00
|
|
|
int
|
|
|
|
LLVMFuzzerTestOneInput (const guint8 * data, size_t size)
|
2017-10-29 07:15:21 +00:00
|
|
|
{
|
|
|
|
GError *err = NULL;
|
|
|
|
GstDiscoverer *dc;
|
|
|
|
gint timeout = 10;
|
|
|
|
GstDiscovererInfo *info;
|
2017-11-01 13:10:05 +00:00
|
|
|
static gboolean initialized = FALSE;
|
2017-10-29 07:15:21 +00:00
|
|
|
|
|
|
|
if (!initialized) {
|
2017-11-01 07:50:25 +00:00
|
|
|
/* We want critical warnings to assert so we can fix them */
|
2018-11-28 10:09:28 +00:00
|
|
|
g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL);
|
2017-11-01 08:45:36 +00:00
|
|
|
g_log_set_default_handler (custom_logger, NULL);
|
2017-10-29 07:15:21 +00:00
|
|
|
|
|
|
|
/* Only initialize and register plugins once */
|
|
|
|
gst_init (NULL, NULL);
|
2017-12-06 07:41:59 +00:00
|
|
|
|
|
|
|
#ifndef LOCAL_FUZZ_BUILD
|
2018-11-28 10:09:28 +00:00
|
|
|
GST_PLUGIN_STATIC_REGISTER (coreelements);
|
|
|
|
GST_PLUGIN_STATIC_REGISTER (playback);
|
|
|
|
GST_PLUGIN_STATIC_REGISTER (typefindfunctions);
|
|
|
|
GST_PLUGIN_STATIC_REGISTER (app);
|
|
|
|
GST_PLUGIN_STATIC_REGISTER (ogg);
|
|
|
|
GST_PLUGIN_STATIC_REGISTER (theora);
|
|
|
|
GST_PLUGIN_STATIC_REGISTER (vorbis);
|
2017-12-06 07:41:59 +00:00
|
|
|
#endif
|
2017-11-01 13:10:05 +00:00
|
|
|
|
|
|
|
initialized = TRUE;
|
2017-10-29 07:15:21 +00:00
|
|
|
}
|
2018-11-28 10:09:28 +00:00
|
|
|
|
2017-10-29 07:15:21 +00:00
|
|
|
dc = gst_discoverer_new (timeout * GST_SECOND, &err);
|
|
|
|
if (G_UNLIKELY (dc == NULL)) {
|
|
|
|
g_print ("Error initializing: %s\n", err->message);
|
|
|
|
g_clear_error (&err);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
fuzztesting_data = data;
|
|
|
|
fuzztesting_size = size;
|
2018-11-28 10:09:28 +00:00
|
|
|
|
2017-10-29 07:15:21 +00:00
|
|
|
/* Connect to source-setup signal to give the data */
|
|
|
|
g_signal_connect (dc, "source-setup", (GCallback) appsrc_configuration, NULL);
|
2018-11-28 10:09:28 +00:00
|
|
|
|
2017-10-29 07:15:21 +00:00
|
|
|
info = gst_discoverer_discover_uri (dc, "appsrc://", &err);
|
|
|
|
g_clear_error (&err);
|
|
|
|
if (info)
|
|
|
|
gst_discoverer_info_unref (info);
|
2018-11-28 10:09:28 +00:00
|
|
|
|
2017-10-29 07:15:21 +00:00
|
|
|
g_object_unref (dc);
|
2018-11-28 10:09:28 +00:00
|
|
|
|
2017-10-29 07:15:21 +00:00
|
|
|
return 0;
|
2018-11-28 10:09:28 +00:00
|
|
|
}
|