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

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

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

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

    // Decode data
    strm.next_in = (unsigned char *)(Data + 2);
    strm.avail_in = Size - 2;
    strm.next_out = dest;
    strm.avail_out = (Size - 2) * 4;
    aec_buffer_encode(&strm);

    // Encode data
Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
34
35
36
37
    strm.next_in = (unsigned char *)(Data + 2);
    strm.avail_in = Size - 2;
    strm.next_out = dest;
    strm.avail_out = (Size - 2) * 4;
38
39
    aec_buffer_decode(&strm);

Mathis Rosenhauer's avatar
Mathis Rosenhauer committed
40
41
42
    free(dest);
    return 0;
}