-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheckpoint_codec_fuzzer.cpp
More file actions
60 lines (55 loc) · 1.94 KB
/
Copy pathcheckpoint_codec_fuzzer.cpp
File metadata and controls
60 lines (55 loc) · 1.94 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
#include "fuzz_common.hpp"
#include "foundation/serialization/state_codec.hpp"
#include <chrono>
#include <cstddef>
#include <cstdint>
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data, std::size_t size)
{
try {
const auto input = lgc::fuzz::inputToString(data, size);
const auto parts = lgc::fuzz::splitInput(input, 2);
const lgc::JsonDecodeLimits limits {
.maxBytes_ = 64 * 1024,
.maxDepth_ = 32,
.maxStringBytes_ = 16 * 1024,
.maxArrayItems_ = 4096,
.maxObjectFields_ = 4096,
.maxNodes_ = 16 * 1024,
};
lgc::JsonCheckpointCodec codec(limits);
const lgc::Payload checkpointPayload {
.contentType_ = "application/vnd.langgraph.checkpoint+json",
.data_ = parts[0],
};
auto checkpoint = codec.decode(checkpointPayload);
if (checkpoint.isOk()) {
auto encoded = codec.encode(*checkpoint);
if (encoded.isOk())
(void)codec.decode(*encoded);
}
const lgc::Payload writePayload {
.contentType_ = "application/vnd.langgraph.checkpoint.write+json",
.data_ = parts[1],
};
auto write = codec.decodeWrite(writePayload);
if (write.isOk()) {
auto encoded = codec.encodeWrite(*write);
if (encoded.isOk())
(void)codec.decodeWrite(*encoded);
}
auto state = lgc::State::fromJson(parts[0], limits);
if (state.isOk()) {
auto synthetic = codec.encode(lgc::Checkpoint {
.threadId_ = "fuzz-thread",
.checkpointId_ = "fuzz-checkpoint",
.step_ = 1,
.state_ = *state,
.createdAt_ = std::chrono::system_clock::now(),
});
if (synthetic.isOk())
(void)codec.decode(*synthetic);
}
} catch (...) {
}
return 0;
}