mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 14:57:35 +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
39
Meta/Lagom/Fuzzers/AudioFuzzerCommon.h
Normal file
39
Meta/Lagom/Fuzzers/AudioFuzzerCommon.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
|
||||
* Copyright (c) 2023, kleines Filmröllchen <filmroellchen@serenityos.org>
|
||||
* Copyright (c) 2021-2023, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Concepts.h>
|
||||
#include <AK/MemoryStream.h>
|
||||
#include <LibAudio/Loader.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
template<typename LoaderPluginType>
|
||||
requires(IsBaseOf<Audio::LoaderPlugin, LoaderPluginType>)
|
||||
int fuzz_audio_loader(uint8_t const* data, size_t size)
|
||||
{
|
||||
auto const bytes = ReadonlyBytes { data, size };
|
||||
auto stream = try_make<FixedMemoryStream>(bytes).release_value();
|
||||
auto audio_or_error = LoaderPluginType::create(move(stream));
|
||||
|
||||
if (audio_or_error.is_error())
|
||||
return 0;
|
||||
|
||||
auto audio = audio_or_error.release_value();
|
||||
|
||||
for (;;) {
|
||||
auto samples = audio->load_chunks(4 * KiB);
|
||||
if (samples.is_error())
|
||||
return 0;
|
||||
if (samples.value().size() == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue