fuzz_target.cc 1.11 KB
Newer Older
Kurt Schwehr's avatar
Kurt Schwehr committed
1
2
3
#include <cstddef>
#include <cstdint>
#include <cstdlib>
4
#include <vector>
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
5
6
7
8
9
10
#include "libaec.h"

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
    if (Size < 2)
        return 0;

11
12
    std::vector<unsigned char> dest(Size * 4);
    aec_stream strm;
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
13
14
15
    strm.bits_per_sample = (Data[0] & 0x1f) | 1;
    strm.block_size = 8 << (Data[1] & 3);
    strm.rsi = 2;
16

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
17
18
19
20
21
    strm.flags = AEC_DATA_PREPROCESS;
    if (Data[1] & 0x80)
        strm.flags |= AEC_DATA_MSB;
    if (Data[1] & 0x40)
        strm.flags |= AEC_DATA_SIGNED;
22
23
24
    if (strm.bits_per_sample <= 24 &&
        strm.bits_per_sample > 16 &&
        Data[1] & 0x10)
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
25
        strm.flags |= AEC_DATA_3BYTE;
26
27

    // Decode data
28
    strm.next_in = reinterpret_cast<const unsigned char *>(Data) + 2;
29
    strm.avail_in = Size - 2;
30
31
    strm.next_out = dest.data();
    strm.avail_out = dest.size();
32
    aec_buffer_decode(&strm);
33
34

    // Encode data
35
    strm.next_in = reinterpret_cast<const unsigned char *>(Data) + 2;
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
36
    strm.avail_in = Size - 2;
37
38
    strm.next_out = dest.data();
    strm.avail_out = dest.size();
39
    aec_buffer_encode(&strm);
40

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
41
42
    return 0;
}