提交 c65fbb25 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

fuzzer: some progress

上级 7ddd0001
...@@ -5,7 +5,7 @@ This document is intended for **mediasoup** developers. ...@@ -5,7 +5,7 @@ This document is intended for **mediasoup** developers.
## Makefile ## Makefile
The root folder of the project contains a `Makefile` to build the mediasoup worker subproject (under the `worker/` folder). The `worker` folder contains a `Makefile` to build the mediasoup worker subproject.
### `make` ### `make`
...@@ -66,10 +66,6 @@ $ npm install -g gulp-cli ...@@ -66,10 +66,6 @@ $ npm install -g gulp-cli
The default task runs the `gulp:lint` and `gulp:test` tasks. The default task runs the `gulp:lint` and `gulp:test` tasks.
### `gulp rtpcapabilities`
Reads **mediasoup** [supported RTP capabilities](https://github.com/versatica/mediasoup/blob/master/lib/supportedRtpCapabilities.js) and inserts them into the worker C++ code. After that, `make Release` and/or `make Debug` must be called.
### `gulp lint` ### `gulp lint`
Runs both the `lint:node` and `lint:worker` gulp tasks. Runs both the `lint:node` and `lint:worker` gulp tasks.
......
...@@ -100,7 +100,7 @@ gulp.task('tidy:worker', gulp.series('tidy:worker:prepare', 'tidy:worker:run')); ...@@ -100,7 +100,7 @@ gulp.task('tidy:worker', gulp.series('tidy:worker:prepare', 'tidy:worker:run'));
gulp.task('test:node', shell.task( gulp.task('test:node', shell.task(
[ [
'if type make &> /dev/null; then make; fi', 'if type make &> /dev/null; then make -C worker; fi',
`tap --bail --color --reporter=spec ${nodeTests.join(' ')}` `tap --bail --color --reporter=spec ${nodeTests.join(' ')}`
], ],
{ {
...@@ -112,7 +112,7 @@ gulp.task('test:node', shell.task( ...@@ -112,7 +112,7 @@ gulp.task('test:node', shell.task(
gulp.task('test:worker', shell.task( gulp.task('test:worker', shell.task(
[ [
'./worker/deps/lcov/bin/lcov --directory ./ --zerocounters', './worker/deps/lcov/bin/lcov --directory ./ --zerocounters',
'if type make &> /dev/null; then make test; fi', 'if type make &> /dev/null; then make test -C worker; fi',
`cd worker && ./out/${process.env.MEDIASOUP_BUILDTYPE === 'Debug' ? `cd worker && ./out/${process.env.MEDIASOUP_BUILDTYPE === 'Debug' ?
'Debug' : 'Release'}/mediasoup-worker-test --invisibles --use-colour=yes ` + 'Debug' : 'Release'}/mediasoup-worker-test --invisibles --use-colour=yes ` +
`${process.env.MEDIASOUP_TEST_TAGS || ''}` `${process.env.MEDIASOUP_TEST_TAGS || ''}`
......
...@@ -52,6 +52,6 @@ ...@@ -52,6 +52,6 @@
"scripts": { "scripts": {
"lint": "gulp lint", "lint": "gulp lint",
"test": "gulp test", "test": "gulp test",
"postinstall": "make Release" "postinstall": "make Release -C worker"
} }
} }
...@@ -6,7 +6,9 @@ ...@@ -6,7 +6,9 @@
# environment variable set by the user. # environment variable set by the user.
PYTHON ?= $(shell command -v python2 2> /dev/null || echo python) PYTHON ?= $(shell command -v python2 2> /dev/null || echo python)
.PHONY: default Release Debug test test-Release test-Debug xcode clean clean-all .PHONY: \
default Release Debug test test-Release test-Debug fuzzer-run \
fuzzer-docker-build fuzzer-docker-run xcode clean clean-all
default: default:
ifeq ($(MEDIASOUP_BUILDTYPE),Debug) ifeq ($(MEDIASOUP_BUILDTYPE),Debug)
...@@ -16,12 +18,12 @@ else ...@@ -16,12 +18,12 @@ else
endif endif
Release: Release:
cd worker && $(PYTHON) ./scripts/configure.py -R mediasoup-worker $(PYTHON) ./scripts/configure.py -R mediasoup-worker
$(MAKE) BUILDTYPE=Release -C worker/out $(MAKE) BUILDTYPE=Release -C out
Debug: Debug:
cd worker && $(PYTHON) ./scripts/configure.py -R mediasoup-worker $(PYTHON) ./scripts/configure.py -R mediasoup-worker
$(MAKE) BUILDTYPE=Debug -C worker/out $(MAKE) BUILDTYPE=Debug -C out
test: test:
ifeq ($(MEDIASOUP_BUILDTYPE),Debug) ifeq ($(MEDIASOUP_BUILDTYPE),Debug)
...@@ -31,39 +33,45 @@ else ...@@ -31,39 +33,45 @@ else
endif endif
test-Release: test-Release:
cd worker && $(PYTHON) ./scripts/configure.py -R mediasoup-worker-test $(PYTHON) ./scripts/configure.py -R mediasoup-worker-test
$(MAKE) BUILDTYPE=Release -C worker/out $(MAKE) BUILDTYPE=Release -C out
test-Debug: test-Debug:
cd worker && $(PYTHON) ./scripts/configure.py -R mediasoup-worker-test $(PYTHON) ./scripts/configure.py -R mediasoup-worker-test
$(MAKE) BUILDTYPE=Debug -C worker/out $(MAKE) BUILDTYPE=Debug -C out
xcode: xcode:
cd worker && $(PYTHON) ./scripts/configure.py --format=xcode $(PYTHON) ./scripts/configure.py --format=xcode
build-fuzzer: fuzzer-run:
$(PYTHON) ./scripts/configure.py -R mediasoup-worker-fuzzer
$(MAKE) BUILDTYPE=Fuzzer -C out
fuzzer-docker-build:
ifeq ($(DOCKER_NO_CACHE),true) ifeq ($(DOCKER_NO_CACHE),true)
cd worker && docker build -f fuzzer/Dockerfile --no-cache --tag mediasoup/fuzzer:latest . docker build -f fuzzer/Dockerfile --no-cache --tag mediasoup/fuzzer:latest .
else else
cd worker && docker build -f fuzzer/Dockerfile --tag mediasoup/fuzzer:latest . docker build -f fuzzer/Dockerfile --tag mediasoup/fuzzer:latest .
endif endif
# TODO: Remove the volume. Not needed. # TODO: Remove the volume. Not needed.
run-fuzzer: fuzzer-docker-run:
cd worker/fuzzer && docker run --name=mediasoupFuzzer -v $(shell pwd)/worker/fuzzer/deleteme:/volume -it --rm mediasoup/fuzzer:latest docker run --name=mediasoupFuzzer -v $(shell pwd)/fuzzer/deleteme:/volume -it --rm mediasoup/fuzzer:latest
# docker exec mediasoupFuzzer CC=clang CXX=clang++ make fuzzer-run
clean: clean:
$(RM) -rf worker/out/Release/mediasoup-worker $(RM) -rf out/Release/mediasoup-worker
$(RM) -rf worker/out/Release/obj.target/mediasoup-worker $(RM) -rf out/Release/obj.target/mediasoup-worker
$(RM) -rf worker/out/Release/mediasoup-worker-test $(RM) -rf out/Release/mediasoup-worker-test
$(RM) -rf worker/out/Release/obj.target/mediasoup-worker-test $(RM) -rf out/Release/obj.target/mediasoup-worker-test
$(RM) -rf worker/out/Debug/mediasoup-worker $(RM) -rf out/Debug/mediasoup-worker
$(RM) -rf worker/out/Debug/obj.target/mediasoup-worker $(RM) -rf out/Debug/obj.target/mediasoup-worker
$(RM) -rf worker/out/Debug/mediasoup-worker-test $(RM) -rf out/Debug/mediasoup-worker-test
$(RM) -rf worker/out/Debug/obj.target/mediasoup-worker-test $(RM) -rf out/Debug/obj.target/mediasoup-worker-test
clean-all: clean-all:
$(RM) -rf worker/out $(RM) -rf out
$(RM) -rf worker/mediasoup-worker.xcodeproj $(RM) -rf worker/mediasoup-worker.xcodeproj
$(RM) -rf worker/mediasoup-worker-test.xcodeproj $(RM) -rf worker/mediasoup-worker-test.xcodeproj
$(RM) -rf worker/deps/*/*.xcodeproj $(RM) -rf worker/deps/*/*.xcodeproj
...@@ -31,6 +31,11 @@ ...@@ -31,6 +31,11 @@
{ {
'GCC_OPTIMIZATION_LEVEL': '0' 'GCC_OPTIMIZATION_LEVEL': '0'
} }
},
'Fuzzer':
{
'defines': [ 'DEBUG' ],
'cflags': [ '-g', '-O0', '-fsanitize=address,fuzzer' ]
} }
}, },
......
FROM ubuntu:16.04
# Install dependencies.
RUN \
set -x \
&& apt-get update \
&& apt-get install --yes \
wget curl subversion screen gcc g++ cmake ninja-build golang autoconf \
libtool apache2 python-dev pkg-config zlib1g-dev libgcrypt11-dev \
libgss-dev libssl-dev libxml2-dev ragel nasm libarchive-dev make \
automake libdbus-1-dev libboost-dev autoconf-archive
WORKDIR /mediasoup/worker
# Install clang 7.0.0.
COPY deps/clang-fuzzer/bin /usr/local/bin
COPY deps/clang-fuzzer/lib/clang /usr/local/lib/clang
# Copy mediasoup source code.
COPY src src
COPY include include
COPY deps deps
COPY scripts scripts
COPY fuzzer fuzzer
COPY Makefile Makefile
COPY mediasoup-worker.gyp mediasoup-worker.gyp
COPY common.gypi common.gypi
COPY fips.gypi fips.gypi
ENV LANG="C.UTF-8"
ENV CC="clang"
ENV CXX="clang++"
# CMD ["/bin/bash"]
CMD ["make", "fuzzer-run"]
#!/usr/bin/env bash
set -e
set -x
echo ">>> compiling fuzzer binary..."
clang++ \
-std=c++11 \
-D MS_LITTLE_ENDIAN \
-g \
-fsanitize=address,fuzzer \
-I include \
fuzzers/fuzz-RtpPacket.cpp src/RTC/RtpPacket.cpp
echo ">>> running fuzzer..."
./a.out
// clang++ -std=c++11 -D MS_LITTLE_ENDIAN -g -fsanitize=address,fuzzer -I include fuzzers/fuzz-RtpPacket.cpp src/RTC/RtpPacket.cpp && ./a.out
#include "RTC/RtpPacket.hpp"
#include <stdint.h>
#include <stddef.h>
#include <iostream>
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t len)
{
// RTC::RtpPacket::IsRtp(data, len);
RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, len);
if (packet)
{
// std::cout << "It is a RTP packet" << std::endl;
// std::cout << "o";
// RTC::RtpPacket* packet2 = RTC::RtpPacket::CreateProbationPacket(data, len);
// if (packet2)
// {
// std::cout << "packet2 probation created!" << std::endl;
// delete packet2;
// }
delete packet;
}
else
{
// std::cout << "It is NOT a RTP packet !!!" << std::endl;
// std::cout << ".";
}
return 0;
}
// int main(int argc, char* argv[])
// {
// uint8_t data[] =
// {
// 0b10010000, 0b00000001, 0, 8,
// 0, 0, 0, 4,
// 0, 0, 0, 5,
// 0xBE, 0xDE, 0, 3, // Extension header
// 0b00010000, 0xFF, 0b00100001, 0xFF,
// 0xFF, 0, 0, 0b00110011,
// 0xFF, 0xFF, 0xFF, 0xFF
// };
// bool ret = RTC::RtpPacket::IsRtp(data, sizeof(data));
// if (ret)
// {
// std::cout << "It is a RTP packet" << std::endl;
// return 0;
// }
// else
// {
// std::cout << "It is NOT a RTP packet !!!" << std::endl;
// return 123;
// }
// }
#ifndef MS_LOGGER_HPP
#define MS_LOGGER_HPP
#include "common.hpp"
#include <cstdio> // std::snprintf(), std::fprintf(), stdout, stderr
#include <cstdlib> // std::abort()
#include <cstring>
#include <string>
#ifdef MS_LOG_DEV
#define _MS_LOG_DEV_ENABLED true
#else
#define _MS_LOG_DEV_ENABLED false
#endif
class Logger
{
public:
static const size_t bufferSize {10000};
static char buffer[];
};
/* Logging macros. */
#define _MS_LOG_SEPARATOR_CHAR_STD "\n"
#define _MS_LOG_STR "%s::%s()"
#define _MS_LOG_STR_DESC _MS_LOG_STR " | "
#define _MS_LOG_ARG MS_CLASS, __FUNCTION__
#ifdef MS_LOG_DEV
#define MS_TRACE() \
do \
{ \
std::fprintf(stdout, "(trace) " _MS_LOG_STR _MS_LOG_SEPARATOR_CHAR_STD, _MS_LOG_ARG); \
std::fflush(stdout); \
} \
while (false)
#define MS_DEBUG_DEV(desc, ...) \
do \
{ \
std::fprintf(stdout, _MS_LOG_STR_DESC desc _MS_LOG_SEPARATOR_CHAR_STD, _MS_LOG_ARG, ##__VA_ARGS__); \
std::fflush(stdout); \
} \
while (false)
#define MS_WARN_DEV(desc, ...) \
do \
{ \
std::fprintf(stderr, _MS_LOG_STR_DESC desc _MS_LOG_SEPARATOR_CHAR_STD, _MS_LOG_ARG, ##__VA_ARGS__); \
std::fflush(stderr); \
} \
while (false)
#else
#define MS_TRACE() ;
#define MS_DEBUG_DEV(desc, ...) ;
#define MS_WARN_DEV(desc, ...) ;
#endif
#define MS_ERROR(desc, ...) \
do \
{ \
std::fprintf(stderr, _MS_LOG_STR_DESC desc _MS_LOG_SEPARATOR_CHAR_STD, _MS_LOG_ARG, ##__VA_ARGS__); \
std::fflush(stderr); \
} \
while (false)
#define MS_ABORT(desc, ...) \
do \
{ \
std::fprintf(stderr, "ABORT" _MS_LOG_STR_DESC desc _MS_LOG_SEPARATOR_CHAR_STD, _MS_LOG_ARG, ##__VA_ARGS__); \
std::fflush(stderr); \
std::abort(); \
} \
while (false)
#define MS_ASSERT(condition, desc, ...) \
if (!(condition)) \
{ \
MS_ABORT("failed assertion `%s': " desc, #condition, ##__VA_ARGS__); \
}
#endif
#ifndef MS_RTC_RTP_PACKET_HPP
#define MS_RTC_RTP_PACKET_HPP
#include "common.hpp"
#include "Utils.hpp"
#include <map>
namespace RTC
{
// Max RTP length.
constexpr size_t RtpBufferSize{ 65536 };
// Max MTU size.
constexpr size_t MtuSize{ 1500 };
class RtpPacket
{
public:
/* Struct for RTP header. */
struct Header
{
#if defined(MS_LITTLE_ENDIAN)
uint8_t csrcCount : 4;
uint8_t extension : 1;
uint8_t padding : 1;
uint8_t version : 2;
uint8_t payloadType : 7;
uint8_t marker : 1;
#elif defined(MS_BIG_ENDIAN)
uint8_t version : 2;
uint8_t padding : 1;
uint8_t extension : 1;
uint8_t csrcCount : 4;
uint8_t marker : 1;
uint8_t payloadType : 7;
#endif
uint16_t sequenceNumber;
uint32_t timestamp;
uint32_t ssrc;
};
private:
/* Struct for RTP extension header. */
struct ExtensionHeader
{
uint16_t id;
uint16_t length; // Size of value in multiples of 4 bytes.
uint8_t value[1];
};
private:
/* Struct for One-Byte extension. */
struct OneByteExtension
{
#if defined(MS_LITTLE_ENDIAN)
uint8_t len : 4;
uint8_t id : 4;
#elif defined(MS_BIG_ENDIAN)
uint8_t id : 4;
uint8_t len : 4;
#endif
uint8_t value[1];
};
private:
/* Struct for Two-Bytes extension. */
struct TwoBytesExtension
{
#if defined(MS_LITTLE_ENDIAN)
uint8_t len : 8;
uint8_t id : 8;
#elif defined(MS_BIG_ENDIAN)
uint8_t id : 8;
uint8_t len : 8;
#endif
uint8_t value[1];
};
public:
static bool IsRtp(const uint8_t* data, size_t len);
static RtpPacket* Parse(const uint8_t* data, size_t len);
static RtpPacket* CreateProbationPacket(const uint8_t* buffer, uint8_t payloadPadding);
public:
RtpPacket(
Header* header,
ExtensionHeader* extensionHeader,
const uint8_t* payload,
size_t payloadLength,
uint8_t payloadPadding,
size_t size);
~RtpPacket();
const uint8_t* GetData() const;
size_t GetSize() const;
uint8_t GetPayloadType() const;
void SetPayloadType(uint8_t payloadType);
bool HasMarker() const;
void SetMarker(bool marker);
void SetPayloadPaddingFlag(bool flag);
uint16_t GetSequenceNumber() const;
void SetSequenceNumber(uint16_t seq);
uint32_t GetTimestamp() const;
void SetTimestamp(uint32_t timestamp);
uint32_t GetSsrc() const;
void SetSsrc(uint32_t ssrc);
bool HasExtensionHeader() const;
uint16_t GetExtensionHeaderId() const;
size_t GetExtensionHeaderLength() const;
uint8_t* GetExtensionHeaderValue() const;
bool HasOneByteExtensions() const;
bool HasTwoBytesExtensions() const;
uint8_t* GetPayload() const;
size_t GetPayloadLength() const;
uint8_t GetPayloadPadding() const;
RtpPacket* Clone(const uint8_t* buffer) const;
void RtxEncode(uint8_t payloadType, uint32_t ssrc, uint16_t seq);
bool RtxDecode(uint8_t payloadType, uint32_t ssrc);
void ShiftPayload(size_t payloadOffset, size_t shift, bool expand = true);
private:
void ParseExtensions();
private:
// Passed by argument.
Header* header{ nullptr };
uint8_t* csrcList{ nullptr };
ExtensionHeader* extensionHeader{ nullptr };
std::map<uint8_t, OneByteExtension*> oneByteExtensions;
std::map<uint8_t, TwoBytesExtension*> twoBytesExtensions;
uint8_t* payload{ nullptr };
size_t payloadLength{ 0 };
uint8_t payloadPadding{ 0 };
size_t size{ 0 }; // Full size of the packet in bytes.
};
/* Inline static methods. */
inline bool RtpPacket::IsRtp(const uint8_t* data, size_t len)
{
// NOTE: RtcpPacket::IsRtcp() must always be called before this method.
auto header = const_cast<Header*>(reinterpret_cast<const Header*>(data));
return (
(len >= sizeof(Header)) &&
// DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes
(data[0] > 127 && data[0] < 192) &&
// RTP Version must be 2.
(header->version == 2));
}
/* Inline instance methods. */
inline const uint8_t* RtpPacket::GetData() const
{
return (const uint8_t*)this->header;
}
inline size_t RtpPacket::GetSize() const
{
return this->size;
}
inline uint8_t RtpPacket::GetPayloadType() const
{
return this->header->payloadType;
}
inline void RtpPacket::SetPayloadType(uint8_t payloadType)
{
this->header->payloadType = payloadType;
}
inline bool RtpPacket::HasMarker() const
{
return this->header->marker;
}
inline void RtpPacket::SetMarker(bool marker)
{
this->header->marker = marker;
}
inline void RtpPacket::SetPayloadPaddingFlag(bool flag)
{
this->header->padding = flag;
}
inline uint16_t RtpPacket::GetSequenceNumber() const
{
return uint16_t{ ntohs(this->header->sequenceNumber) };
}
inline void RtpPacket::SetSequenceNumber(uint16_t seq)
{
this->header->sequenceNumber = uint16_t{ htons(seq) };
}
inline uint32_t RtpPacket::GetTimestamp() const
{
return uint32_t{ ntohl(this->header->timestamp) };
}
inline void RtpPacket::SetTimestamp(uint32_t timestamp)
{
this->header->timestamp = uint32_t{ htonl(timestamp) };
}
inline uint32_t RtpPacket::GetSsrc() const
{
return uint32_t{ ntohl(this->header->ssrc) };
}
inline void RtpPacket::SetSsrc(uint32_t ssrc)
{
this->header->ssrc = uint32_t{ htonl(ssrc) };
}
inline bool RtpPacket::HasExtensionHeader() const
{
return (this->extensionHeader ? true : false);
}
inline uint16_t RtpPacket::GetExtensionHeaderId() const
{
if (!this->extensionHeader)
return 0;
return uint16_t{ ntohs(this->extensionHeader->id) };
}
inline size_t RtpPacket::GetExtensionHeaderLength() const
{
if (!this->extensionHeader)
return 0;
return static_cast<size_t>(ntohs(this->extensionHeader->length) * 4);
}
inline uint8_t* RtpPacket::GetExtensionHeaderValue() const
{
if (!this->extensionHeader)
return nullptr;
return this->extensionHeader->value;
}
inline bool RtpPacket::HasOneByteExtensions() const
{
return GetExtensionHeaderId() == 0xBEDE;
}
inline bool RtpPacket::HasTwoBytesExtensions() const
{
return (GetExtensionHeaderId() & 0b1111111111110000) == 0b0001000000000000;
}
inline uint8_t* RtpPacket::GetPayload() const
{
return this->payload;
}
inline size_t RtpPacket::GetPayloadLength() const
{
return this->payloadLength;
}
inline uint8_t RtpPacket::GetPayloadPadding() const
{
return this->payloadPadding;
}
} // namespace RTC
#endif
#ifndef MS_UTILS_HPP
#define MS_UTILS_HPP
#include "common.hpp"
#include <string>
namespace Utils
{
class Byte
{
public:
/**
* Getters below get value in Host Byte Order.
* Setters below set value in Network Byte Order.
*/
static uint8_t Get1Byte(const uint8_t* data, size_t i);
static uint16_t Get2Bytes(const uint8_t* data, size_t i);
static uint32_t Get3Bytes(const uint8_t* data, size_t i);
static uint32_t Get4Bytes(const uint8_t* data, size_t i);
static uint64_t Get8Bytes(const uint8_t* data, size_t i);
static void Set1Byte(uint8_t* data, size_t i, uint8_t value);
static void Set2Bytes(uint8_t* data, size_t i, uint16_t value);
static void Set3Bytes(uint8_t* data, size_t i, uint32_t value);
static void Set4Bytes(uint8_t* data, size_t i, uint32_t value);
static void Set8Bytes(uint8_t* data, size_t i, uint64_t value);
static uint16_t PadTo4Bytes(uint16_t size);
static uint32_t PadTo4Bytes(uint32_t size);
};
/* Inline static methods. */
inline uint8_t Byte::Get1Byte(const uint8_t* data, size_t i)
{
return data[i];
}
inline uint16_t Byte::Get2Bytes(const uint8_t* data, size_t i)
{
return uint16_t{ data[i + 1] } | uint16_t{ data[i] } << 8;
}
inline uint32_t Byte::Get3Bytes(const uint8_t* data, size_t i)
{
return uint32_t{ data[i + 2] } | uint32_t{ data[i + 1] } << 8 | uint32_t{ data[i] } << 16;
}
inline uint32_t Byte::Get4Bytes(const uint8_t* data, size_t i)
{
return uint32_t{ data[i + 3] } | uint32_t{ data[i + 2] } << 8 | uint32_t{ data[i + 1] } << 16 |
uint32_t{ data[i] } << 24;
}
inline uint64_t Byte::Get8Bytes(const uint8_t* data, size_t i)
{
return uint64_t{ Byte::Get4Bytes(data, i) } << 32 | Byte::Get4Bytes(data, i + 4);
}
inline void Byte::Set1Byte(uint8_t* data, size_t i, uint8_t value)
{
data[i] = value;
}
inline void Byte::Set2Bytes(uint8_t* data, size_t i, uint16_t value)
{
data[i + 1] = static_cast<uint8_t>(value);
data[i] = static_cast<uint8_t>(value >> 8);
}
inline void Byte::Set3Bytes(uint8_t* data, size_t i, uint32_t value)
{
data[i + 2] = static_cast<uint8_t>(value);
data[i + 1] = static_cast<uint8_t>(value >> 8);
data[i] = static_cast<uint8_t>(value >> 16);
}
inline void Byte::Set4Bytes(uint8_t* data, size_t i, uint32_t value)
{
data[i + 3] = static_cast<uint8_t>(value);
data[i + 2] = static_cast<uint8_t>(value >> 8);
data[i + 1] = static_cast<uint8_t>(value >> 16);
data[i] = static_cast<uint8_t>(value >> 24);
}
inline void Byte::Set8Bytes(uint8_t* data, size_t i, uint64_t value)
{
data[i + 7] = static_cast<uint8_t>(value);
data[i + 6] = static_cast<uint8_t>(value >> 8);
data[i + 5] = static_cast<uint8_t>(value >> 16);
data[i + 4] = static_cast<uint8_t>(value >> 24);
data[i + 3] = static_cast<uint8_t>(value >> 32);
data[i + 2] = static_cast<uint8_t>(value >> 40);
data[i + 1] = static_cast<uint8_t>(value >> 48);
data[i] = static_cast<uint8_t>(value >> 56);
}
inline uint16_t Byte::PadTo4Bytes(uint16_t size)
{
// If size is not multiple of 32 bits then pad it.
if (size & 0x03)
return (size & 0xFFFC) + 4;
else
return size;
}
inline uint32_t Byte::PadTo4Bytes(uint32_t size)
{
// If size is not multiple of 32 bits then pad it.
if (size & 0x03)
return (size & 0xFFFFFFFC) + 4;
else
return size;
}
class String
{
public:
static void ToLowerCase(std::string& str);
};
inline void String::ToLowerCase(std::string& str)
{
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
}
class Time
{
// Seconds from Jan 1, 1900 to Jan 1, 1970.
static constexpr uint32_t UnixNtpOffset{ 0x83AA7E80 };
// NTP fractional unit.
static constexpr uint64_t NtpFractionalUnit{ 1LL << 32 };
public:
struct Ntp
{
uint32_t seconds;
uint32_t fractions;
};
static Time::Ntp TimeMs2Ntp(uint64_t ms);
static bool IsNewerTimestamp(uint32_t timestamp, uint32_t prevTimestamp);
static uint32_t LatestTimestamp(uint32_t timestamp1, uint32_t timestamp2);
};
inline Time::Ntp Time::TimeMs2Ntp(uint64_t ms)
{
Ntp ntp;
ntp.seconds = ms / 1000;
ntp.fractions =
static_cast<uint32_t>(static_cast<double>(ms % 1000) / 1000 * Utils::Time::NtpFractionalUnit);
return ntp;
}
inline bool Time::IsNewerTimestamp(uint32_t timestamp, uint32_t prevTimestamp)
{
// Distinguish between elements that are exactly 0x80000000 apart.
// If t1>t2 and |t1-t2| = 0x80000000: IsNewer(t1,t2)=true,
// IsNewer(t2,t1)=false
// rather than having IsNewer(t1,t2) = IsNewer(t2,t1) = false.
if (static_cast<uint32_t>(timestamp - prevTimestamp) == 0x80000000)
return timestamp > prevTimestamp;
return timestamp != prevTimestamp &&
static_cast<uint32_t>(timestamp - prevTimestamp) < 0x80000000;
}
inline uint32_t Time::LatestTimestamp(uint32_t timestamp1, uint32_t timestamp2)
{
return IsNewerTimestamp(timestamp1, timestamp2) ? timestamp1 : timestamp2;
}
} // namespace Utils
#endif
#ifndef MS_COMMON_HPP
#define MS_COMMON_HPP
#include <algorithm> // std::transform(), std::find(), std::min(), std::max()
#include <arpa/inet.h> // htonl(), htons(), ntohl(), ntohs()
#include <cinttypes> // PRIu64, etc
#include <cstddef> // size_t
#include <cstdint> // uint8_t, etc
#include <memory> // std::addressof()
#include <netinet/in.h> // sockaddr_in, sockaddr_in6
#include <sys/socket.h> // struct sockaddr, struct sockaddr_storage, AF_INET, AF_INET6
#endif
差异被折叠。
#include "RTC/RtpPacket.hpp"
#include <stdint.h>
#include <stddef.h>
#include <iostream>
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t len)
{
RTC::RtpPacket::IsRtp(data, len);
RTC::RtpPacket* packet = RTC::RtpPacket::Parse(data, len);
if (packet)
{
std::cout << "It is a RTP packet" << std::endl;
delete packet;
}
else
{
// std::cout << "It is NOT a RTP packet !!!" << std::endl;
// std::cout << ".";
}
return 0;
}
...@@ -261,7 +261,7 @@ ...@@ -261,7 +261,7 @@
}, },
{ {
'target_name': 'mediasoup-worker-test', 'target_name': 'mediasoup-worker-test',
'defines': [ 'MS_TEST', 'MS_LOG_STD' ], 'defines': [ 'MS_LOG_STD' ],
'sources': 'sources':
[ [
# C++ source files # C++ source files
...@@ -301,15 +301,25 @@ ...@@ -301,15 +301,25 @@
[ [
'test/include' 'test/include'
], ],
'xcode_settings': 'xcode_settings':
{ {
'OTHER_CPLUSPLUSFLAGS': [ 'OTHER_CPLUSPLUSFLAGS': [
'--coverage' '--coverage'
], ],
'OTHER_LDFLAGS': [ 'OTHER_LDFLAGS': [
'--coverage' '--coverage'
] ]
} }
},
{
'target_name': 'mediasoup-worker-fuzzer',
'defines': [ 'MS_LOG_STD' ],
'sources':
[
# C++ source files
'fuzzer/fuzzer.cpp'
],
'include_dirs': []
} }
] ]
} }
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论