strawberry/fuzz/fuzz_manifest.cpp
trvon adb40e5b62
Add compressed event store
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>
2026-10-25 18:17:17 -06:00

41 lines
1.8 KiB
C++

// MANIFEST decoding over untrusted bytes. Must never crash; whatever it
// accepts must contain only safe file names and re-encode to an equal
// manifest. Control byte bit 1 fixes block CRCs so mutations reach the
// record/field logic.
#include "strawberry/store/manifest.hpp"
#include <cstdint>
#include <string>
using namespace strawberry::store;
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
if (size == 0) return 0;
std::string bytes(reinterpret_cast<const char*>(data) + 1, size - 1);
if ((data[0] & 2) != 0) {
std::size_t off = kManifestHeaderBytes;
while (off + kBlockHeaderBytes <= bytes.size()) {
uint32_t stored = 0;
for (int i = 0; i < 4; ++i) stored |= static_cast<uint32_t>(static_cast<uint8_t>(bytes[off + 12 + i])) << (8 * i);
const std::size_t avail = bytes.size() - off - kBlockHeaderBytes;
const std::size_t n = stored < avail ? stored : avail;
const uint32_t pc = crc32c(bytes.data() + off + kBlockHeaderBytes, n);
for (int i = 0; i < 4; ++i) bytes[off + 20 + i] = static_cast<char>(pc >> (8 * i));
const uint32_t hc = crc32c(bytes.data() + off, 24);
for (int i = 0; i < 4; ++i) bytes[off + 24 + i] = static_cast<char>(hc >> (8 * i));
off += kBlockHeaderBytes + n;
}
}
Manifest m;
if (!decode_manifest(bytes, m)) return 0;
for (const auto& s : m.segments) {
if (!valid_store_file_name(s.file) || s.file.find('/') != std::string::npos) __builtin_trap();
}
for (const auto& d : m.dictionaries) {
if (!valid_store_file_name(d.file) || d.file.find('/') != std::string::npos) __builtin_trap();
}
Manifest back;
if (!decode_manifest(encode_manifest(m), back) || !(back == m)) __builtin_trap();
return 0;
}