File: fuzz_target.cc

package info (click to toggle)
libaec 1.1.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,272 kB
  • sloc: ansic: 3,746; sh: 109; makefile: 75; cpp: 34
file content (42 lines) | stat: -rw-r--r-- 1,134 bytes parent folder | download | duplicates (4)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <vector>
#include "libaec.h"

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

    std::vector<unsigned char> dest(Size * 4);
    aec_stream strm;
    strm.bits_per_sample = (Data[0] & 0x1f) | 1;
    strm.block_size = 8 << (Data[1] & 3);
    strm.rsi = 2;

    strm.flags = AEC_DATA_PREPROCESS;
    if (Data[1] & 0x80)
        strm.flags |= AEC_DATA_MSB;
    if (Data[1] & 0x40)
        strm.flags |= AEC_DATA_SIGNED;
    if (strm.bits_per_sample <= 24 &&
        strm.bits_per_sample > 16 &&
        Data[1] & 0x10)
        strm.flags |= AEC_DATA_3BYTE;

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

    // Encode data
    strm.next_in = reinterpret_cast<const unsigned char *>(Data) + 2;
    strm.avail_in = Size - 2;
    strm.next_out = dest.data();
    strm.avail_out = dest.size();
    aec_buffer_encode(&strm);

    return 0;
}