mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 11:58:13 +00:00
Meta/Fuzzers: Extract common audio fuzzing code
Apart from the class used audio fuzzers have identical behavior: Create a memory stream from the fuzzer input and pass this to the loader, then try to load audio until an error occurs. Since the loader plugins need to have the same static create() function anyways for LibAudio itself, we can unify the fuzzer implementations and reduce code duplication.
This commit is contained in:
parent
088cc4ea73
commit
8df714ff1e
5 changed files with 50 additions and 86 deletions
|
@ -1,32 +1,13 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
|
||||
* Copyright (c) 2023, kleines Filmröllchen <filmroellchen@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/MemoryStream.h>
|
||||
#include "AudioFuzzerCommon.h"
|
||||
#include <LibAudio/FlacLoader.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
|
||||
{
|
||||
auto const flac_bytes = ByteBuffer::copy(data, size).release_value();
|
||||
auto flac_data = try_make<FixedMemoryStream>(flac_bytes).release_value();
|
||||
auto flac_or_error = Audio::FlacLoaderPlugin::create(move(flac_data));
|
||||
|
||||
if (flac_or_error.is_error())
|
||||
return 0;
|
||||
|
||||
auto flac = flac_or_error.release_value();
|
||||
|
||||
for (;;) {
|
||||
auto samples = flac->load_chunks(10 * KiB);
|
||||
if (samples.is_error())
|
||||
return 0;
|
||||
if (samples.value().size() == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return fuzz_audio_loader<Audio::FlacLoaderPlugin>(data, size);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue