Bug 1465407 - Add media fuzzing targets. r=jya
authorChristian Holler <choller@mozilla.com>
Tue, 16 Jul 2019 14:50:17 +0000
changeset 546675 5fa9c790f64b20fa1986c4bc7ea5dba8ca5e0042
parent 546674 e2965eee48fe016a62e85d16e4be3f841fc780f9
child 546676 9a87637d6ebee396eaf267584d3c4888e68733c6
push id2165
push userffxbld-merge
push dateMon, 14 Oct 2019 16:30:58 +0000
treeherdermozilla-release@0eae18af659f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1465407
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1465407 - Add media fuzzing targets. r=jya Depends on D35776 Differential Revision: https://phabricator.services.mozilla.com/D35777
dom/media/flac/moz.build
dom/media/fuzz/FuzzMedia.cpp
dom/media/fuzz/moz.build
dom/media/hls/moz.build
dom/media/moz.build
dom/media/mp3/moz.build
dom/media/mp4/moz.build
dom/media/ogg/moz.build
dom/media/platforms/moz.build
dom/media/platforms/omx/moz.build
dom/media/platforms/wmf/moz.build
dom/media/wave/moz.build
dom/media/webm/moz.build
media/ffvpx/ffvpxcommon.mozbuild
media/libmkv/moz.build
media/libnestegg/src/moz.build
media/libogg/moz.build
media/libopus/moz.build
media/libvorbis/moz.build
--- a/dom/media/flac/moz.build
+++ b/dom/media/flac/moz.build
@@ -17,8 +17,11 @@ UNIFIED_SOURCES += [
 ]
 
 CXXFLAGS += CONFIG['MOZ_LIBVPX_CFLAGS']
 
 FINAL_LIBRARY = 'xul'
 
 if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
     CXXFLAGS += ['-Wno-error=shadow']
+
+# Add libFuzzer configuration directives
+include('/tools/fuzzing/libfuzzer-config.mozbuild')
new file mode 100644
--- /dev/null
+++ b/dom/media/fuzz/FuzzMedia.cpp
@@ -0,0 +1,62 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "ADTSDemuxer.h"
+#include "Benchmark.h"
+#include "BufferMediaResource.h"
+#include "FlacDemuxer.h"
+#include "FuzzingInterface.h"
+#include "mozilla/AbstractThread.h"
+#include "MP3Demuxer.h"
+#include "MP4Demuxer.h"
+#include "OggDemuxer.h"
+#include "systemservices/MediaUtils.h"
+#include "WaveDemuxer.h"
+#include "WebMDemuxer.h"
+
+using namespace mozilla;
+
+class FuzzRunner {
+ public:
+  explicit FuzzRunner(Benchmark* aBenchmark) : mBenchmark(aBenchmark) {}
+
+  void Run() {
+    mBenchmark->Init();
+    media::Await(
+        GetMediaThreadPool(MediaThreadType::PLAYBACK), mBenchmark->Run(),
+        [&](uint32_t aDecodeFps) {}, [&](const MediaResult& aError) {});
+    return;
+  }
+
+ private:
+  RefPtr<Benchmark> mBenchmark;
+};
+
+static int FuzzingInitMedia(int* argc, char*** argv) {
+  /* Generic no-op initialization used for all targets */
+  return 0;
+}
+
+#define MOZ_MEDIA_FUZZER(_name)                                         \
+  static int FuzzingRunMedia##_name(const uint8_t* data, size_t size) { \
+    if (!size) {                                                        \
+        return 0;                                                       \
+    }                                                                   \
+    RefPtr<BufferMediaResource> resource =                              \
+        new BufferMediaResource(data, size);                            \
+    FuzzRunner runner(new Benchmark(new _name##Demuxer(resource)));     \
+    runner.Run();                                                       \
+    return 0;                                                           \
+  }                                                                     \
+  MOZ_FUZZING_INTERFACE_RAW(FuzzingInitMedia, FuzzingRunMedia##_name,   \
+                            Media##_name);
+
+MOZ_MEDIA_FUZZER(ADTS);
+MOZ_MEDIA_FUZZER(Flac);
+MOZ_MEDIA_FUZZER(MP3);
+MOZ_MEDIA_FUZZER(MP4);
+MOZ_MEDIA_FUZZER(Ogg);
+MOZ_MEDIA_FUZZER(WAV);
+MOZ_MEDIA_FUZZER(WebM);
new file mode 100644
--- /dev/null
+++ b/dom/media/fuzz/moz.build
@@ -0,0 +1,29 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+Library('FuzzingMedia')
+
+SOURCES += [
+    'FuzzMedia.cpp',
+]
+
+include('/ipc/chromium/chromium-config.mozbuild')
+
+LOCAL_INCLUDES += [
+    '/dom/media',
+    '/dom/media/encoder',
+    '/dom/media/gmp',
+    '/dom/media/hls',
+    '/dom/media/mp4',
+    '/dom/media/ogg',
+    '/dom/media/platforms',
+    '/dom/media/platforms/agnostic',
+]
+
+FINAL_LIBRARY = 'xul-gtest'
+
+# Add libFuzzer configuration directives
+include('/tools/fuzzing/libfuzzer-config.mozbuild')
--- a/dom/media/hls/moz.build
+++ b/dom/media/hls/moz.build
@@ -17,8 +17,11 @@ UNIFIED_SOURCES += [
 ]
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
 
 if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
     CXXFLAGS += ['-Wno-error=shadow']
+
+# Add libFuzzer configuration directives
+include('/tools/fuzzing/libfuzzer-config.mozbuild')
--- a/dom/media/moz.build
+++ b/dom/media/moz.build
@@ -64,16 +64,24 @@ if CONFIG['MOZ_FMP4']:
 
 if CONFIG['MOZ_WEBRTC']:
     DIRS += ['bridge']
 
 TEST_DIRS += [
     'gtest',
 ]
 
+# Add libFuzzer configuration directives
+include('/tools/fuzzing/libfuzzer-config.mozbuild')
+
+if CONFIG['FUZZING_INTERFACES']:
+    TEST_DIRS += [
+        'fuzz'
+    ]
+
 MOCHITEST_MANIFESTS += [
     'test/mochitest.ini',
     'tests/mochitest/identity/mochitest.ini',
 ]
 
 if CONFIG['MOZ_WEBRTC']:
     MOCHITEST_MANIFESTS += ['tests/mochitest/mochitest.ini']
     WEBRTC_SIGNALLING_TEST_MANIFESTS += ['tests/mochitest/steeplechase.ini']
--- a/dom/media/mp3/moz.build
+++ b/dom/media/mp3/moz.build
@@ -12,8 +12,11 @@ EXPORTS += [
 
 UNIFIED_SOURCES += [
     'MP3Decoder.cpp',
     'MP3Demuxer.cpp',
     'MP3FrameParser.cpp',
 ]
 
 FINAL_LIBRARY = 'xul'
+
+# Add libFuzzer configuration directives
+include('/tools/fuzzing/libfuzzer-config.mozbuild')
--- a/dom/media/mp4/moz.build
+++ b/dom/media/mp4/moz.build
@@ -35,8 +35,11 @@ UNIFIED_SOURCES += [
 ]
 
 FINAL_LIBRARY = 'xul'
 
 # Suppress warnings for now.
 CXXFLAGS += [
     '-Wno-sign-compare',
 ]
+
+# Add libFuzzer configuration directives
+include('/tools/fuzzing/libfuzzer-config.mozbuild')
--- a/dom/media/ogg/moz.build
+++ b/dom/media/ogg/moz.build
@@ -18,8 +18,11 @@ UNIFIED_SOURCES += [
     'OggCodecStore.cpp',
     'OggDecoder.cpp',
     'OggDemuxer.cpp',
     'OggWriter.cpp',
     'OpusParser.cpp',
 ]
 
 FINAL_LIBRARY = 'xul'
+
+# Add libFuzzer configuration directives
+include('/tools/fuzzing/libfuzzer-config.mozbuild')
--- a/dom/media/platforms/moz.build
+++ b/dom/media/platforms/moz.build
@@ -122,8 +122,11 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'andr
         'android/AndroidDecoderModule.cpp',
         'android/RemoteDataDecoder.cpp',
     ]
 
 FINAL_LIBRARY = 'xul'
 
 if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
     CXXFLAGS += ['-Wno-error=shadow']
+
+# Add libFuzzer configuration directives
+include('/tools/fuzzing/libfuzzer-config.mozbuild')
--- a/dom/media/platforms/omx/moz.build
+++ b/dom/media/platforms/omx/moz.build
@@ -29,8 +29,11 @@ if CONFIG['MOZ_OMX']:
 FINAL_LIBRARY = 'xul'
 
 if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
     CXXFLAGS += ['-Wno-error=shadow']
 
 # Avoid warnings from third-party code that we can not modify.
 if CONFIG['CC_TYPE'] == 'clang-cl':
     CXXFLAGS += ['-Wno-invalid-source-encoding']
+
+# Add libFuzzer configuration directives
+include('/tools/fuzzing/libfuzzer-config.mozbuild')
--- a/dom/media/platforms/wmf/moz.build
+++ b/dom/media/platforms/wmf/moz.build
@@ -27,8 +27,11 @@ SOURCES += [
     'WMFUtils.cpp',
 ]
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
 
 CXXFLAGS += CONFIG['MOZ_CAIRO_CFLAGS']
+
+# Add libFuzzer configuration directives
+include('/tools/fuzzing/libfuzzer-config.mozbuild')
--- a/dom/media/wave/moz.build
+++ b/dom/media/wave/moz.build
@@ -13,8 +13,11 @@ UNIFIED_SOURCES += [
     'WaveDecoder.cpp',
     'WaveDemuxer.cpp',
 ]
 
 FINAL_LIBRARY = 'xul'
 
 if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
     CXXFLAGS += ['-Wno-error=shadow']
+
+# Add libFuzzer configuration directives
+include('/tools/fuzzing/libfuzzer-config.mozbuild')
--- a/dom/media/webm/moz.build
+++ b/dom/media/webm/moz.build
@@ -24,8 +24,11 @@ if CONFIG['MOZ_WEBM_ENCODER']:
     ]
 
 CXXFLAGS += CONFIG['MOZ_LIBVPX_CFLAGS']
 
 FINAL_LIBRARY = 'xul'
 
 if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
     CXXFLAGS += ['-Wno-error=shadow']
+
+# Add libFuzzer configuration directives
+include('/tools/fuzzing/libfuzzer-config.mozbuild')
--- a/media/ffvpx/ffvpxcommon.mozbuild
+++ b/media/ffvpx/ffvpxcommon.mozbuild
@@ -70,8 +70,11 @@ if CONFIG['CC_TYPE'] == 'clang-cl':
 DEFINES['HAVE_AV_CONFIG_H'] = True
 
 if CONFIG['MOZ_DEBUG']:
     # Enable all assertions in debug builds.
     DEFINES['ASSERT_LEVEL'] = 2
 elif not CONFIG['RELEASE_OR_BETA']:
     # Enable fast assertions in opt builds of Nightly and Aurora.
     DEFINES['ASSERT_LEVEL'] = 1
+
+# Add libFuzzer configuration directives
+include('/tools/fuzzing/libfuzzer-config.mozbuild')
--- a/media/libmkv/moz.build
+++ b/media/libmkv/moz.build
@@ -23,8 +23,11 @@ SOURCES += [
     'EbmlWriter.c',
     'WebMElement.c',
 ]
 
 FINAL_LIBRARY = 'gkmedias'
 
 # We allow warnings for third-party code that can be updated from upstream.
 AllowCompilerWarnings()
+
+# Add libFuzzer configuration directives
+include('/tools/fuzzing/libfuzzer-config.mozbuild')
--- a/media/libnestegg/src/moz.build
+++ b/media/libnestegg/src/moz.build
@@ -7,8 +7,11 @@
 UNIFIED_SOURCES += [
     'nestegg.c',
 ]
 
 FINAL_LIBRARY = 'gkmedias'
 
 # We allow warnings for third-party code that can be updated from upstream.
 AllowCompilerWarnings()
+
+# Add libFuzzer configuration directives
+include('/tools/fuzzing/libfuzzer-config.mozbuild')
--- a/media/libogg/moz.build
+++ b/media/libogg/moz.build
@@ -15,8 +15,11 @@ EXPORTS.ogg += [
 
 UNIFIED_SOURCES += [
     'src/ogg_alloc.c',
     'src/ogg_bitwise.c',
     'src/ogg_framing.c',
 ]
 
 FINAL_LIBRARY = 'gkmedias'
+
+# Add libFuzzer configuration directives
+include('/tools/fuzzing/libfuzzer-config.mozbuild')
--- a/media/libopus/moz.build
+++ b/media/libopus/moz.build
@@ -133,8 +133,11 @@ if CONFIG['CPU_ARCH'] == 'aarch64' and C
     SOURCES += silk_sources_arm_neon_intr
     if not CONFIG['MOZ_SAMPLE_TYPE_FLOAT32']:
         SOURCES += silk_sources_fixed_arm_neon_intr
 
 # Suppress warnings in third-party code.
 if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
     if CONFIG['CC_TYPE'] == 'clang':
         CFLAGS += ['-Wno-#pragma-messages']
+
+# Add libFuzzer configuration directives
+include('/tools/fuzzing/libfuzzer-config.mozbuild')
--- a/media/libvorbis/moz.build
+++ b/media/libvorbis/moz.build
@@ -51,8 +51,11 @@ if CONFIG['OS_ARCH'] == 'SunOS':
 # We allow warnings for third-party code that can be updated from upstream.
 AllowCompilerWarnings()
 
 FINAL_LIBRARY = 'gkmedias'
 
 # Suppress warnings in third-party code.
 if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
     CFLAGS += ['-Wno-uninitialized']
+
+# Add libFuzzer configuration directives
+#include('/tools/fuzzing/libfuzzer-config.mozbuild')