Updated buffer_reader_fuzzer
Implemented google c++ code style changes for buffer_reader_fuzzer exec/s: 3649 Test: ./buffer_reader_fuzzer Bug: 312374669 Change-Id: I53bd247f6c95202d7a5e86115aa060c61821d49c
This commit is contained in:
committed by
Aditya Wazir
parent
2b3de00a36
commit
363447d00c
@@ -47,20 +47,20 @@ const std::string kInitDataVersions[] = {
|
||||
|
||||
const std::string kMultipleWidevinePsshBox = wvutil::a2bs_hex(
|
||||
// first PSSH box, Widevine with single keys
|
||||
"00000042" // atom size
|
||||
"70737368" // atom type "pssh"
|
||||
"00000000" // v0, flags=0
|
||||
"edef8ba979d64acea3c827dcd51d21ed" // system id (Widevine)
|
||||
"00000022" // data size
|
||||
"00000042" // atom size
|
||||
"70737368" // atom type "pssh"
|
||||
"00000000" // v0, flags=0
|
||||
"edef8ba979d64acea3c827dcd51d21ed" // system id (Widevine)
|
||||
"00000022" // data size
|
||||
// data:
|
||||
"08011a0d7769646576696e655f74657374220f73747265616d696e675f636c697031"
|
||||
|
||||
// second PSSH box, Widevine with entitled keys
|
||||
"000001fb" // atom size
|
||||
"70737368" // atom type="pssh"
|
||||
"00000000" // v0, flags=0
|
||||
"edef8ba979d64acea3c827dcd51d21ed" // system id (Widevine)
|
||||
"000001db" // data size
|
||||
"000001fb" // atom size
|
||||
"70737368" // atom type="pssh"
|
||||
"00000000" // v0, flags=0
|
||||
"edef8ba979d64acea3c827dcd51d21ed" // system id (Widevine)
|
||||
"000001db" // data size
|
||||
// data:
|
||||
"220b47726f7570563254657374381448"
|
||||
"e3dc959b065002580272580a10668093"
|
||||
@@ -93,7 +93,7 @@ const std::string kMultipleWidevinePsshBox = wvutil::a2bs_hex(
|
||||
"3c8f389223c0f3621522101946f0c2a3"
|
||||
"d543101cc842bbec2d0b30");
|
||||
|
||||
const std::string kHLSData =
|
||||
const std::string kHlsData =
|
||||
"EXT-X-KEY: METHOD=SAMPLE-AES, "
|
||||
"URI=”data:text/plain;base64,eyANCiAgICJwcm92aWRlciI6Im1sYmFtaGJvIiwNCiAg"
|
||||
"ICJjb250ZW50X2lkIjoiMjAxNV9UZWFycyIsDQogICAia2V5X2lkcyI6DQogICBbDQo"
|
||||
@@ -103,179 +103,189 @@ const std::string kHLSData =
|
||||
"KEYFORMAT=”com.widevine”, "
|
||||
"KEYFORMATVERSIONS=”1”";
|
||||
|
||||
const std::string kHLSMethodParse = "EXT-X-KEY: METHOD=";
|
||||
const std::string kHlsMethodParse = "EXT-X-KEY: METHOD=";
|
||||
const std::string KUriParse = "\"URI=\"data:text/plain;base64,";
|
||||
const std::string kIVParse = "\"IV=";
|
||||
const std::string kIvParse = "\"IV=";
|
||||
const std::string kKeyFormatParse = "\"KEYFORMAT=\"";
|
||||
const std::string kKeyFormatVersionParse = "\"KEYFORMATVERSIONS=\"";
|
||||
|
||||
class BufferReaderFuzzer {
|
||||
public:
|
||||
BufferReaderFuzzer(const uint8_t *data, size_t size) : mFdp(data, size){};
|
||||
void process();
|
||||
std::string setPartialRandomHLSData();
|
||||
std::string setRandomHLSData();
|
||||
public:
|
||||
BufferReaderFuzzer(const uint8_t *data, size_t size) : fdp_(data, size){};
|
||||
void Process();
|
||||
std::string SetPartialRandomHlsData();
|
||||
std::string SetRandomHlsData();
|
||||
|
||||
private:
|
||||
FuzzedDataProvider mFdp;
|
||||
private:
|
||||
FuzzedDataProvider fdp_;
|
||||
};
|
||||
|
||||
std::string BufferReaderFuzzer::setPartialRandomHLSData() {
|
||||
std::string hlsMethod =
|
||||
kHLSMethodParse +
|
||||
(mFdp.ConsumeBool() ? mFdp.ConsumeRandomLengthString(kMaxByte)
|
||||
: mFdp.PickValueInArray(kHlsMethod)) +
|
||||
std::string BufferReaderFuzzer::SetPartialRandomHlsData() {
|
||||
std::string hls_method =
|
||||
kHlsMethodParse +
|
||||
(fdp_.ConsumeBool() ? fdp_.ConsumeRandomLengthString(kMaxByte)
|
||||
: fdp_.PickValueInArray(kHlsMethod)) +
|
||||
", \"";
|
||||
std::string uri = KUriParse +
|
||||
(mFdp.ConsumeBool()
|
||||
? mFdp.ConsumeRandomLengthString(kMaxByte)
|
||||
(fdp_.ConsumeBool()
|
||||
? fdp_.ConsumeRandomLengthString(kMaxByte)
|
||||
: "eyANCiAgICJwcm92aWRlciI6Im1sYmFtaGJvIiwNCiAg\" \
|
||||
\"ICJjb250ZW50X2lkIjoiMjAxNV9UZWFycyIsDQogICAia2V5X2lkcyI6DQogICBbDQo\" \
|
||||
\"gICAgICAiMzcxZTEzNWUxYTk4NWQ3NWQxOThhN2Y0MTAyMGRjMjMiDQogICBdDQp9DQ\" \
|
||||
\"o=") + ", \"";
|
||||
std::string iv =
|
||||
kIVParse +
|
||||
((mFdp.ConsumeBool() ? mFdp.ConsumeRandomLengthString(kMaxByte)
|
||||
kIvParse +
|
||||
((fdp_.ConsumeBool() ? fdp_.ConsumeRandomLengthString(kMaxByte)
|
||||
: "0x6df49213a781e338628d0e9c812d328e,")) +
|
||||
"\"";
|
||||
std::string keyFormat =
|
||||
std::string key_format =
|
||||
kKeyFormatParse +
|
||||
(mFdp.ConsumeBool()
|
||||
? ("\"" + mFdp.ConsumeRandomLengthString(kMaxByte) + "\"")
|
||||
(fdp_.ConsumeBool()
|
||||
? ("\"" + fdp_.ConsumeRandomLengthString(kMaxByte) + "\"")
|
||||
: "com.widevine\", \"");
|
||||
std::string keyFormatVersion =
|
||||
std::string key_format_version =
|
||||
kKeyFormatVersionParse +
|
||||
(mFdp.ConsumeBool() ? mFdp.ConsumeRandomLengthString(kMaxByte) : "\"1\"");
|
||||
(fdp_.ConsumeBool() ? fdp_.ConsumeRandomLengthString(kMaxByte) : "\"1\"");
|
||||
|
||||
std::string result = hlsMethod + uri + iv + keyFormat + keyFormatVersion;
|
||||
std::string result = hls_method + uri + iv + key_format + key_format_version;
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string BufferReaderFuzzer::setRandomHLSData() {
|
||||
std::string hlsMethod;
|
||||
if(mFdp.ConsumeBool()){
|
||||
hlsMethod = kHLSMethodParse;
|
||||
}
|
||||
hlsMethod += mFdp.ConsumeRandomLengthString(kMaxByte) + ", \"";
|
||||
std::string BufferReaderFuzzer::SetRandomHlsData() {
|
||||
std::string hls_method;
|
||||
if (fdp_.ConsumeBool()) {
|
||||
hls_method = kHlsMethodParse;
|
||||
}
|
||||
hls_method += fdp_.ConsumeRandomLengthString(kMaxByte) + ", \"";
|
||||
|
||||
std::string uri;
|
||||
if(mFdp.ConsumeBool()){
|
||||
uri = KUriParse;
|
||||
}
|
||||
uri += mFdp.ConsumeRandomLengthString(kMaxByte) + ", \"";
|
||||
if (fdp_.ConsumeBool()) {
|
||||
uri = KUriParse;
|
||||
}
|
||||
uri += fdp_.ConsumeRandomLengthString(kMaxByte) + ", \"";
|
||||
|
||||
std::string iv;
|
||||
if(mFdp.ConsumeBool()){
|
||||
iv = kIVParse;
|
||||
if (fdp_.ConsumeBool()) {
|
||||
iv = kIvParse;
|
||||
}
|
||||
iv += mFdp.ConsumeRandomLengthString(kMaxByte) + "\"";
|
||||
iv += fdp_.ConsumeRandomLengthString(kMaxByte) + "\"";
|
||||
|
||||
std::string keyFormat;
|
||||
if(mFdp.ConsumeBool()){
|
||||
keyFormat = kKeyFormatParse;
|
||||
std::string key_format;
|
||||
if (fdp_.ConsumeBool()) {
|
||||
key_format = kKeyFormatParse;
|
||||
}
|
||||
keyFormat += mFdp.ConsumeRandomLengthString(kMaxByte) + "\"";
|
||||
key_format += fdp_.ConsumeRandomLengthString(kMaxByte) + "\"";
|
||||
|
||||
std::string keyFormatVersion;
|
||||
if(mFdp.ConsumeBool()){
|
||||
keyFormatVersion = kKeyFormatVersionParse;
|
||||
std::string key_format_version;
|
||||
if (fdp_.ConsumeBool()) {
|
||||
key_format_version = kKeyFormatVersionParse;
|
||||
}
|
||||
keyFormatVersion += mFdp.ConsumeRandomLengthString(kMaxByte);
|
||||
key_format_version += fdp_.ConsumeRandomLengthString(kMaxByte);
|
||||
|
||||
std::string result = hlsMethod + uri + iv + keyFormat + keyFormatVersion;
|
||||
std::string result = hls_method + uri + iv + key_format + key_format_version;
|
||||
return result;
|
||||
}
|
||||
|
||||
void BufferReaderFuzzer::process() {
|
||||
void BufferReaderFuzzer::Process() {
|
||||
std::vector<uint8_t> raw_data =
|
||||
fdp_.ConsumeBytes<uint8_t>(fdp_.ConsumeIntegral<size_t>());
|
||||
BufferReader reader(raw_data.data(), raw_data.size());
|
||||
|
||||
std::vector<uint8_t> rawData =
|
||||
mFdp.ConsumeBytes<uint8_t>(mFdp.ConsumeIntegral<size_t>());
|
||||
BufferReader reader(rawData.data(), rawData.size());
|
||||
|
||||
std::string type = mFdp.PickValueInArray(kInitDataTypes);
|
||||
std::string type = fdp_.PickValueInArray(kInitDataTypes);
|
||||
std::string data;
|
||||
|
||||
if (type == ISO_BMFF_VIDEO_MIME_TYPE || type == ISO_BMFF_AUDIO_MIME_TYPE ||
|
||||
type == CENC_INIT_DATA_FORMAT) {
|
||||
data = mFdp.ConsumeBool()
|
||||
? wvutil::a2bs_hex(mFdp.ConsumeRandomLengthString(kMaxByte))
|
||||
data = fdp_.ConsumeBool()
|
||||
? wvutil::a2bs_hex(fdp_.ConsumeRandomLengthString(kMaxByte))
|
||||
: kMultipleWidevinePsshBox;
|
||||
} else if (type == HLS_INIT_DATA_FORMAT) {
|
||||
data = mFdp.PickValueInArray({kHLSData, setPartialRandomHLSData(),
|
||||
setRandomHLSData()});
|
||||
data = fdp_.PickValueInArray(
|
||||
{kHlsData, SetPartialRandomHlsData(), SetRandomHlsData()});
|
||||
} else {
|
||||
data = mFdp.ConsumeRandomLengthString(kMaxByte);
|
||||
data = fdp_.ConsumeRandomLengthString(kMaxByte);
|
||||
}
|
||||
|
||||
std::string initDataType =
|
||||
mFdp.ConsumeBool() ? mFdp.ConsumeRandomLengthString(kMaxByte) : type;
|
||||
std::string init_data_type =
|
||||
fdp_.ConsumeBool() ? fdp_.ConsumeRandomLengthString(kMaxByte) : type;
|
||||
std::string version =
|
||||
mFdp.ConsumeBool() ? mFdp.PickValueInArray(kInitDataVersions) : "";
|
||||
InitializationData initData(initDataType, data, version);
|
||||
fdp_.ConsumeBool() ? fdp_.PickValueInArray(kInitDataVersions) : "";
|
||||
InitializationData init_data(init_data_type, data, version);
|
||||
|
||||
while (mFdp.remaining_bytes()) {
|
||||
auto invokeBufferReaderAPIs =
|
||||
mFdp.PickValueInArray<const std::function<void()>>({
|
||||
while (fdp_.remaining_bytes()) {
|
||||
auto invoke_buffer_reader_API =
|
||||
fdp_.PickValueInArray<const std::function<void()>>({
|
||||
[&]() {
|
||||
uint8_t placeholder;
|
||||
mFdp.ConsumeBool() ? reader.Read1(&placeholder)
|
||||
uint8_t place_holder;
|
||||
fdp_.ConsumeBool() ? reader.Read1(&place_holder)
|
||||
: reader.Read1(nullptr);
|
||||
},
|
||||
|
||||
[&]() {
|
||||
uint16_t placeholder;
|
||||
mFdp.ConsumeBool() ? reader.Read2(&placeholder) : reader.Read2(nullptr);
|
||||
uint16_t place_holder;
|
||||
fdp_.ConsumeBool() ? reader.Read2(&place_holder)
|
||||
: reader.Read2(nullptr);
|
||||
},
|
||||
|
||||
[&]() {
|
||||
int16_t placeholder;
|
||||
mFdp.ConsumeBool() ? reader.Read2s(&placeholder)
|
||||
int16_t place_holder;
|
||||
fdp_.ConsumeBool() ? reader.Read2s(&place_holder)
|
||||
: reader.Read2s(nullptr);
|
||||
},
|
||||
|
||||
[&]() {
|
||||
int64_t placeholder;
|
||||
mFdp.ConsumeBool() ? reader.Read8s(&placeholder)
|
||||
int64_t place_holder;
|
||||
fdp_.ConsumeBool() ? reader.Read8s(&place_holder)
|
||||
: reader.Read8s(nullptr);
|
||||
},
|
||||
|
||||
[&]() {
|
||||
uint64_t placeholder;
|
||||
mFdp.ConsumeBool() ? reader.Read8(&placeholder) : reader.Read8(nullptr);
|
||||
uint64_t place_holder;
|
||||
fdp_.ConsumeBool() ? reader.Read8(&place_holder)
|
||||
: reader.Read8(nullptr);
|
||||
},
|
||||
|
||||
[&]() {
|
||||
int64_t placeholder;
|
||||
mFdp.ConsumeBool() ? reader.Read4sInto8s(&placeholder)
|
||||
int64_t place_holder;
|
||||
fdp_.ConsumeBool() ? reader.Read4sInto8s(&place_holder)
|
||||
: reader.Read4sInto8s(nullptr);
|
||||
},
|
||||
|
||||
[&]() {
|
||||
std::string placeholder;
|
||||
mFdp.ConsumeBool() ? reader.ReadString(&placeholder, mFdp.ConsumeIntegralInRange<size_t>(kMinSize, kMaxSize))
|
||||
: reader.ReadString(nullptr, mFdp.ConsumeIntegralInRange<size_t>(kMinSize, kMaxSize));
|
||||
std::string place_holder;
|
||||
fdp_.ConsumeBool()
|
||||
? reader.ReadString(
|
||||
&place_holder,
|
||||
fdp_.ConsumeIntegralInRange<size_t>(kMinSize, kMaxSize))
|
||||
: reader.ReadString(
|
||||
nullptr, fdp_.ConsumeIntegralInRange<size_t>(kMinSize,
|
||||
kMaxSize));
|
||||
},
|
||||
|
||||
[&]() {
|
||||
std::vector<uint8_t> placeholder;
|
||||
mFdp.ConsumeBool() ? reader.ReadVec(&placeholder, mFdp.ConsumeIntegralInRange<size_t>(kMinSize, kMaxSize))
|
||||
: reader.ReadVec(nullptr, mFdp.ConsumeIntegralInRange<size_t>(kMinSize, kMaxSize));
|
||||
std::vector<uint8_t> place_holder;
|
||||
fdp_.ConsumeBool()
|
||||
? reader.ReadVec(
|
||||
&place_holder,
|
||||
fdp_.ConsumeIntegralInRange<size_t>(kMinSize, kMaxSize))
|
||||
: reader.ReadVec(nullptr, fdp_.ConsumeIntegralInRange<size_t>(
|
||||
kMinSize, kMaxSize));
|
||||
},
|
||||
|
||||
[&]() { initData.ExtractWrappedKeys(); },
|
||||
[&]() { init_data.ExtractWrappedKeys(); },
|
||||
|
||||
[&]() { initData.DumpToLogs(); },
|
||||
[&]() { init_data.DumpToLogs(); },
|
||||
|
||||
[&]() { initData.WidevineSystemID(); },
|
||||
[&]() { init_data.WidevineSystemID(); },
|
||||
|
||||
});
|
||||
|
||||
invokeBufferReaderAPIs();
|
||||
invoke_buffer_reader_API();
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
BufferReaderFuzzer bufferReaderFuzzer(data, size);
|
||||
bufferReaderFuzzer.process();
|
||||
BufferReaderFuzzer buffer_reader_fuzzer(data, size);
|
||||
buffer_reader_fuzzer.Process();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user