summaryrefslogtreecommitdiff
path: root/Meta/Lagom/Fuzzers/FuzzMP3Loader.cpp
blob: f9b8a92c646ef086a1b9d9c5861142ac5207ed71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
 * Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <LibAudio/MP3Loader.h>
#include <stddef.h>
#include <stdint.h>

extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
{
    auto flac_data = ByteBuffer::copy(data, size).release_value();
    auto mp3 = make<Audio::MP3LoaderPlugin>(flac_data);

    if (mp3->initialize().is_error())
        return 1;

    for (;;) {
        auto samples = mp3->get_more_samples();
        if (samples.is_error())
            return 2;
        if (samples.value().size() > 0)
            break;
    }

    return 0;
}