zstd block codec (CRC32C, varint tagged records), segment files with sealed footers and block index, crash-atomic MANIFEST, LogStore (lock, recovery, rolls, orphaning, heal with backoff), the evidence view, and the legacy unqlite store kept for import. Property tests under injected faults and crashes, a differential test against the old store, and fuzz targets for every decoder. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
53 lines
2 KiB
C++
53 lines
2 KiB
C++
// Evidence-stream records (indicator, node, edge, finding) over untrusted
|
|
// bytes, then replayed into the in-memory view. Decoders must never crash;
|
|
// whatever they accept must round-trip; the view must stay queryable.
|
|
|
|
#include "../src/store/evidence_records.hpp"
|
|
#include "../src/store/evidence_view.hpp"
|
|
#include "strawberry/store/codec.hpp"
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
|
|
using namespace strawberry;
|
|
using namespace strawberry::store;
|
|
|
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
|
const std::string_view in(reinterpret_cast<const char*>(data), size);
|
|
{
|
|
IndicatorEntry a, b;
|
|
if (decode_indicator(in, a) && (!decode_indicator(encode_indicator(a), b) || !same_indicator(a, b))) __builtin_trap();
|
|
GraphNode n, m;
|
|
if (decode_node(in, n) && (!decode_node(encode_node(n), m) || !same_node(n, m))) __builtin_trap();
|
|
GraphEdge e, f;
|
|
if (decode_edge(in, e) && (!decode_edge(encode_edge(e), f) || EvidenceView::edge_key(e) != EvidenceView::edge_key(f)))
|
|
__builtin_trap();
|
|
FindingRecord x, y;
|
|
if (decode_finding(in, x) && (!decode_finding(encode_finding(x), y) || !same_finding(x, y))) __builtin_trap();
|
|
}
|
|
// Interpret the input as a record stream and replay it, with a
|
|
// transaction around the second half that is rolled back.
|
|
EvidenceView view;
|
|
RecordReader records(in);
|
|
RecordView rec;
|
|
std::size_t n = 0;
|
|
bool txn = false;
|
|
while (records.next(rec)) {
|
|
if (n == 4 && !txn) {
|
|
view.begin();
|
|
txn = true;
|
|
}
|
|
(void) view.apply(rec.type, rec.payload);
|
|
++n;
|
|
}
|
|
const auto before_nodes = view.node_count();
|
|
if (txn) view.rollback();
|
|
if (txn && view.node_count() > before_nodes) __builtin_trap();
|
|
for (const auto& node : view.nodes("")) {
|
|
(void) view.edges_of(node.id);
|
|
(void) view.related(node.id, 3);
|
|
}
|
|
(void) view.findings();
|
|
(void) view.all_indicators();
|
|
return 0;
|
|
}
|