// 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 #include 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(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(static_cast(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(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(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; }