-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuzz_ase.cpp
More file actions
74 lines (66 loc) · 1.45 KB
/
fuzz_ase.cpp
File metadata and controls
74 lines (66 loc) · 1.45 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright (C) 2020-2022 Igara Studio S.A.
#include "base/ints.h"
#include "dio/aseprite_decoder.h"
#include "dio/decode_delegate.h"
#include "dio/file_interface.h"
#include <cassert>
#include <cstdlib>
class MemoryFileInterface : public dio::FileInterface {
public:
MemoryFileInterface(const uint8_t* data, size_t size)
: m_data(data)
, m_size(size)
, m_pos(0)
, m_ok(true) {
}
bool ok() const override {
return m_ok;
}
size_t tell() override { return m_pos; }
void seek(size_t absPos) override {
if (absPos >= m_size) {
m_pos = m_size;
m_ok = false;
}
else {
m_pos = absPos;
m_ok = true;
}
}
size_t readBytes(uint8_t* buf, size_t n) override {
if (m_pos+n > m_size)
n = m_size - m_pos;
if (n <= 0)
return 0;
std::copy(m_data+m_pos,
m_data+m_pos+n, buf);
return n;
}
uint8_t read8() override {
if (!m_ok) return 0;
if (m_pos >= m_size) {
m_ok = false;
return 0;
}
return m_data[m_pos++];
}
void write8(uint8_t value) override {
// unused
assert(false);
}
private:
const uint8_t* m_data;
size_t m_size;
size_t m_pos;
bool m_ok;
};
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
MemoryFileInterface file(data, size);
dio::DecodeDelegate delegate;
dio::AsepriteDecoder decoder;
decoder.initialize(&delegate, &file);
if (!decoder.decode())
return 1;
return 0;
}