Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fuzzer codecs #1355

Merged
merged 9 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/Fuzzer.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ The mediasoup-worker fuzzer reads some custom environment variables to decide wh
- `MS_FUZZ_DTLS=1`: Enable DTLS fuzzer.
- `MS_FUZZ_RTP=1`: Enable RTP fuzzer.
- `MS_FUZZ_RTCP=1`: Enable RTCP fuzzer.
- `MS_FUZZ_CODECS=1`: Enable audio/video codecs fuzzer.
- `MS_FUZZ_UTILS=1`: Enable C++ utils fuzzer.
- If none of them is given, then **all** fuzzers are enabled.

Expand Down Expand Up @@ -74,6 +75,12 @@ MS_FUZZ_RTP=1 LSAN_OPTIONS=verbosity=1:log_threads=1 ./out/Release/mediasoup-wor
MS_FUZZ_RTCP=1 LSAN_OPTIONS=verbosity=1:log_threads=1 ./out/Release/mediasoup-worker-fuzzer -artifact_prefix=fuzzer/reports/ -max_len=1400 fuzzer/new-corpus deps/webrtc-fuzzer-corpora/corpora/rtcp-corpus
```

- Detect memory leaks and just fuzz audio/video codecs:

```bash
MS_FUZZ_CODECS=1 LSAN_OPTIONS=verbosity=1:log_threads=1 ./out/Release/mediasoup-worker-fuzzer -artifact_prefix=fuzzer/reports/ -max_len=1400 fuzzer/new-corpus
```

- Detect memory leaks and just fuzz mediasoup-worker C++ utils:

```bash
Expand Down
20 changes: 20 additions & 0 deletions worker/fuzzer/include/RTC/Codecs/FuzzerH264.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef MS_FUZZER_RTC_CODECS_H264_HPP
#define MS_FUZZER_RTC_CODECS_H264_HPP

#include "common.hpp"

namespace Fuzzer
{
namespace RTC
{
namespace Codecs
{
namespace H264
{
void Fuzz(const uint8_t* data, size_t len);
}
} // namespace Codecs
} // namespace RTC
} // namespace Fuzzer

#endif
20 changes: 20 additions & 0 deletions worker/fuzzer/include/RTC/Codecs/FuzzerH264_SVC.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef MS_FUZZER_RTC_CODECS_H264_SVC_HPP
#define MS_FUZZER_RTC_CODECS_H264_SVC_HPP

#include "common.hpp"

namespace Fuzzer
{
namespace RTC
{
namespace Codecs
{
namespace H264_SVC
{
void Fuzz(const uint8_t* data, size_t len);
}
} // namespace Codecs
} // namespace RTC
} // namespace Fuzzer

#endif
20 changes: 20 additions & 0 deletions worker/fuzzer/include/RTC/Codecs/FuzzerOpus.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef MS_FUZZER_RTC_CODECS_OPUS_HPP
#define MS_FUZZER_RTC_CODECS_OPUS_HPP

#include "common.hpp"

namespace Fuzzer
{
namespace RTC
{
namespace Codecs
{
namespace Opus
{
void Fuzz(const uint8_t* data, size_t len);
}
} // namespace Codecs
} // namespace RTC
} // namespace Fuzzer

#endif
20 changes: 20 additions & 0 deletions worker/fuzzer/include/RTC/Codecs/FuzzerVP8.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef MS_FUZZER_RTC_CODECS_VP8_HPP
#define MS_FUZZER_RTC_CODECS_VP8_HPP

#include "common.hpp"

namespace Fuzzer
{
namespace RTC
{
namespace Codecs
{
namespace VP8
{
void Fuzz(const uint8_t* data, size_t len);
}
} // namespace Codecs
} // namespace RTC
} // namespace Fuzzer

#endif
20 changes: 20 additions & 0 deletions worker/fuzzer/include/RTC/Codecs/FuzzerVP9.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef MS_FUZZER_RTC_CODECS_VP9_HPP
#define MS_FUZZER_RTC_CODECS_VP9_HPP

#include "common.hpp"

namespace Fuzzer
{
namespace RTC
{
namespace Codecs
{
namespace VP9
{
void Fuzz(const uint8_t* data, size_t len);
}
} // namespace Codecs
} // namespace RTC
} // namespace Fuzzer

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
88t
Binary file not shown.
14 changes: 14 additions & 0 deletions worker/fuzzer/src/RTC/Codecs/FuzzerH264.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "RTC/Codecs/FuzzerH264.hpp"
#include "RTC/Codecs/H264.hpp"

void Fuzzer::RTC::Codecs::H264::Fuzz(const uint8_t* data, size_t len)
{
::RTC::Codecs::H264::PayloadDescriptor* descriptor = ::RTC::Codecs::H264::Parse(data, len);

if (!descriptor)
{
return;
}

delete descriptor;
}
14 changes: 14 additions & 0 deletions worker/fuzzer/src/RTC/Codecs/FuzzerH264_SVC.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "RTC/Codecs/FuzzerH264_SVC.hpp"
#include "RTC/Codecs/H264_SVC.hpp"

void Fuzzer::RTC::Codecs::H264_SVC::Fuzz(const uint8_t* data, size_t len)
{
::RTC::Codecs::H264_SVC::PayloadDescriptor* descriptor = ::RTC::Codecs::H264_SVC::Parse(data, len);

if (!descriptor)
{
return;
}

delete descriptor;
}
14 changes: 14 additions & 0 deletions worker/fuzzer/src/RTC/Codecs/FuzzerOpus.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "RTC/Codecs/FuzzerOpus.hpp"
#include "RTC/Codecs/Opus.hpp"

void Fuzzer::RTC::Codecs::Opus::Fuzz(const uint8_t* data, size_t len)
{
::RTC::Codecs::Opus::PayloadDescriptor* descriptor = ::RTC::Codecs::Opus::Parse(data, len);

if (!descriptor)
{
return;
}

delete descriptor;
}
14 changes: 14 additions & 0 deletions worker/fuzzer/src/RTC/Codecs/FuzzerVP8.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "RTC/Codecs/FuzzerVP8.hpp"
#include "RTC/Codecs/VP8.hpp"

void Fuzzer::RTC::Codecs::VP8::Fuzz(const uint8_t* data, size_t len)
{
::RTC::Codecs::VP8::PayloadDescriptor* descriptor = ::RTC::Codecs::VP8::Parse(data, len);

if (!descriptor)
{
return;
}

delete descriptor;
}
14 changes: 14 additions & 0 deletions worker/fuzzer/src/RTC/Codecs/FuzzerVP9.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "RTC/Codecs/FuzzerVP9.hpp"
#include "RTC/Codecs/VP9.hpp"

void Fuzzer::RTC::Codecs::VP9::Fuzz(const uint8_t* data, size_t len)
{
::RTC::Codecs::VP9::PayloadDescriptor* descriptor = ::RTC::Codecs::VP9::Parse(data, len);

if (!descriptor)
{
return;
}

delete descriptor;
}
44 changes: 33 additions & 11 deletions worker/fuzzer/src/fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
#include "LogLevel.hpp"
#include "Settings.hpp"
#include "Utils.hpp"
#include "RTC/Codecs/FuzzerH264.hpp"
#include "RTC/Codecs/FuzzerH264_SVC.hpp"
#include "RTC/Codecs/FuzzerOpus.hpp"
#include "RTC/Codecs/FuzzerVP8.hpp"
#include "RTC/Codecs/FuzzerVP9.hpp"
#include "RTC/DtlsTransport.hpp"
#include "RTC/FuzzerDtlsTransport.hpp"
#include "RTC/FuzzerRtpPacket.hpp"
Expand All @@ -23,11 +28,12 @@
#include <stddef.h>
#include <stdint.h>

bool fuzzStun = false;
bool fuzzDtls = false;
bool fuzzRtp = false;
bool fuzzRtcp = false;
bool fuzzUtils = false;
bool fuzzStun = false;
bool fuzzDtls = false;
bool fuzzRtp = false;
bool fuzzRtcp = false;
bool fuzzCodecs = false;
bool fuzzUtils = false;

int Init();

Expand Down Expand Up @@ -62,6 +68,15 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t len)
Fuzzer::RTC::RTCP::Packet::Fuzz(data, len);
}

if (fuzzCodecs)
{
Fuzzer::RTC::Codecs::Opus::Fuzz(data, len);
Fuzzer::RTC::Codecs::VP8::Fuzz(data, len);
Fuzzer::RTC::Codecs::VP9::Fuzz(data, len);
Fuzzer::RTC::Codecs::H264::Fuzz(data, len);
Fuzzer::RTC::Codecs::H264_SVC::Fuzz(data, len);
}

if (fuzzUtils)
{
Fuzzer::Utils::Fuzz(data, len);
Expand Down Expand Up @@ -118,21 +133,28 @@ int Init()

fuzzRtcp = true;
}
if (std::getenv("MS_FUZZ_CODECS") && std::string(std::getenv("MS_FUZZ_CODECS")) == "1")
{
std::cout << "[fuzzer] codecs fuzzer enabled" << std::endl;

fuzzCodecs = true;
}
if (std::getenv("MS_FUZZ_UTILS") && std::string(std::getenv("MS_FUZZ_UTILS")) == "1")
{
std::cout << "[fuzzer] Utils fuzzer enabled" << std::endl;

fuzzUtils = true;
}
if (!fuzzStun && !fuzzDtls && !fuzzRtcp && !fuzzRtp && !fuzzUtils)
if (!fuzzStun && !fuzzDtls && !fuzzRtp && !fuzzRtcp && !fuzzCodecs && !fuzzUtils)
{
std::cout << "[fuzzer] all fuzzers enabled" << std::endl;

fuzzStun = true;
fuzzDtls = true;
fuzzRtp = true;
fuzzRtcp = true;
fuzzUtils = true;
fuzzStun = true;
fuzzDtls = true;
fuzzRtp = true;
fuzzRtcp = true;
fuzzCodecs = true;
fuzzUtils = true;
}

Settings::configuration.logLevel = logLevel;
Expand Down
1 change: 1 addition & 0 deletions worker/include/RTC/Codecs/H264.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace RTC
uint8_t tid{ 0 }; // Temporal layer id.
uint8_t lid{ 0 }; // Spatial layer id.
uint8_t tl0picidx{ 0 }; // TL0PICIDX

// Parsed values.
bool hasLid{ false };
bool hasTid{ false };
Expand Down
5 changes: 5 additions & 0 deletions worker/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,11 @@ executable(
'fuzzer/src/RTC/FuzzerSeqManager.cpp',
'fuzzer/src/RTC/FuzzerStunPacket.cpp',
'fuzzer/src/RTC/FuzzerTrendCalculator.cpp',
'fuzzer/src/RTC/Codecs/FuzzerOpus.cpp',
'fuzzer/src/RTC/Codecs/FuzzerVP8.cpp',
'fuzzer/src/RTC/Codecs/FuzzerVP9.cpp',
'fuzzer/src/RTC/Codecs/FuzzerH264.cpp',
'fuzzer/src/RTC/Codecs/FuzzerH264_SVC.cpp',
'fuzzer/src/RTC/RTCP/FuzzerBye.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackPs.cpp',
'fuzzer/src/RTC/RTCP/FuzzerFeedbackPsAfb.cpp',
Expand Down
11 changes: 11 additions & 0 deletions worker/src/RTC/Codecs/H264_SVC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ namespace RTC
// Single NAL unit packet.
// IDR (instantaneous decoding picture).
case 5:
{
payloadDescriptor->isKeyFrame = true;
}

case 1:
{
payloadDescriptor->slIndex = 0;
Expand All @@ -177,9 +180,15 @@ namespace RTC

break;
}

case 14:
case 20:
{
if (len <= 1)
{
return nullptr;
}

size_t offset{ 1 };
uint8_t byte = data[offset];

Expand Down Expand Up @@ -210,13 +219,15 @@ namespace RTC

break;
}

case 7:
{
payloadDescriptor->isKeyFrame = isStartBit ? true : false;

break;
}
}

return payloadDescriptor;
}

Expand Down
Loading