Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 8cfda79

Browse files
committed
Bug 1465407 - Add media fuzzing targets. r=jya
Depends on D35776 Differential Revision: https://phabricator.services.mozilla.com/D35777 --HG-- extra : moz-landing-system : lando
1 parent af96b9b commit 8cfda79

19 files changed

Lines changed: 147 additions & 0 deletions

File tree

dom/media/flac/moz.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ FINAL_LIBRARY = 'xul'
2222

2323
if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
2424
CXXFLAGS += ['-Wno-error=shadow']
25+
26+
# Add libFuzzer configuration directives
27+
include('/tools/fuzzing/libfuzzer-config.mozbuild')

dom/media/fuzz/FuzzMedia.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2+
/* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+
#include "ADTSDemuxer.h"
7+
#include "Benchmark.h"
8+
#include "BufferMediaResource.h"
9+
#include "FlacDemuxer.h"
10+
#include "FuzzingInterface.h"
11+
#include "mozilla/AbstractThread.h"
12+
#include "MP3Demuxer.h"
13+
#include "MP4Demuxer.h"
14+
#include "OggDemuxer.h"
15+
#include "systemservices/MediaUtils.h"
16+
#include "WaveDemuxer.h"
17+
#include "WebMDemuxer.h"
18+
19+
using namespace mozilla;
20+
21+
class FuzzRunner {
22+
public:
23+
explicit FuzzRunner(Benchmark* aBenchmark) : mBenchmark(aBenchmark) {}
24+
25+
void Run() {
26+
mBenchmark->Init();
27+
media::Await(
28+
GetMediaThreadPool(MediaThreadType::PLAYBACK), mBenchmark->Run(),
29+
[&](uint32_t aDecodeFps) {}, [&](const MediaResult& aError) {});
30+
return;
31+
}
32+
33+
private:
34+
RefPtr<Benchmark> mBenchmark;
35+
};
36+
37+
static int FuzzingInitMedia(int* argc, char*** argv) {
38+
/* Generic no-op initialization used for all targets */
39+
return 0;
40+
}
41+
42+
#define MOZ_MEDIA_FUZZER(_name) \
43+
static int FuzzingRunMedia##_name(const uint8_t* data, size_t size) { \
44+
if (!size) { \
45+
return 0; \
46+
} \
47+
RefPtr<BufferMediaResource> resource = \
48+
new BufferMediaResource(data, size); \
49+
FuzzRunner runner(new Benchmark(new _name##Demuxer(resource))); \
50+
runner.Run(); \
51+
return 0; \
52+
} \
53+
MOZ_FUZZING_INTERFACE_RAW(FuzzingInitMedia, FuzzingRunMedia##_name, \
54+
Media##_name);
55+
56+
MOZ_MEDIA_FUZZER(ADTS);
57+
MOZ_MEDIA_FUZZER(Flac);
58+
MOZ_MEDIA_FUZZER(MP3);
59+
MOZ_MEDIA_FUZZER(MP4);
60+
MOZ_MEDIA_FUZZER(Ogg);
61+
MOZ_MEDIA_FUZZER(WAV);
62+
MOZ_MEDIA_FUZZER(WebM);

dom/media/fuzz/moz.build

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
2+
# vim: set filetype=python:
3+
# This Source Code Form is subject to the terms of the Mozilla Public
4+
# License, v. 2.0. If a copy of the MPL was not distributed with this
5+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
7+
Library('FuzzingMedia')
8+
9+
SOURCES += [
10+
'FuzzMedia.cpp',
11+
]
12+
13+
include('/ipc/chromium/chromium-config.mozbuild')
14+
15+
LOCAL_INCLUDES += [
16+
'/dom/media',
17+
'/dom/media/encoder',
18+
'/dom/media/gmp',
19+
'/dom/media/hls',
20+
'/dom/media/mp4',
21+
'/dom/media/ogg',
22+
'/dom/media/platforms',
23+
'/dom/media/platforms/agnostic',
24+
]
25+
26+
FINAL_LIBRARY = 'xul-gtest'
27+
28+
# Add libFuzzer configuration directives
29+
include('/tools/fuzzing/libfuzzer-config.mozbuild')

dom/media/hls/moz.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ FINAL_LIBRARY = 'xul'
2222

2323
if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
2424
CXXFLAGS += ['-Wno-error=shadow']
25+
26+
# Add libFuzzer configuration directives
27+
include('/tools/fuzzing/libfuzzer-config.mozbuild')

dom/media/moz.build

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ TEST_DIRS += [
6969
'gtest',
7070
]
7171

72+
# Add libFuzzer configuration directives
73+
include('/tools/fuzzing/libfuzzer-config.mozbuild')
74+
75+
if CONFIG['FUZZING_INTERFACES']:
76+
TEST_DIRS += [
77+
'fuzz'
78+
]
79+
7280
MOCHITEST_MANIFESTS += [
7381
'test/mochitest.ini',
7482
'tests/mochitest/identity/mochitest.ini',

dom/media/mp3/moz.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ UNIFIED_SOURCES += [
1717
]
1818

1919
FINAL_LIBRARY = 'xul'
20+
21+
# Add libFuzzer configuration directives
22+
include('/tools/fuzzing/libfuzzer-config.mozbuild')

dom/media/mp4/moz.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ FINAL_LIBRARY = 'xul'
4040
CXXFLAGS += [
4141
'-Wno-sign-compare',
4242
]
43+
44+
# Add libFuzzer configuration directives
45+
include('/tools/fuzzing/libfuzzer-config.mozbuild')

dom/media/ogg/moz.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ UNIFIED_SOURCES += [
2323
]
2424

2525
FINAL_LIBRARY = 'xul'
26+
27+
# Add libFuzzer configuration directives
28+
include('/tools/fuzzing/libfuzzer-config.mozbuild')

dom/media/platforms/moz.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,6 @@ FINAL_LIBRARY = 'xul'
127127

128128
if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
129129
CXXFLAGS += ['-Wno-error=shadow']
130+
131+
# Add libFuzzer configuration directives
132+
include('/tools/fuzzing/libfuzzer-config.mozbuild')

dom/media/platforms/omx/moz.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@ if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
3434
# Avoid warnings from third-party code that we can not modify.
3535
if CONFIG['CC_TYPE'] == 'clang-cl':
3636
CXXFLAGS += ['-Wno-invalid-source-encoding']
37+
38+
# Add libFuzzer configuration directives
39+
include('/tools/fuzzing/libfuzzer-config.mozbuild')

0 commit comments

Comments
 (0)