Loading src/backend.cpp +8 −20 Original line number Diff line number Diff line Loading @@ -2913,30 +2913,18 @@ std::vector<std::uint8_t> ClusterMediaBackend::export_db_to_buffer_impl() const bin_write_str(oss, m.media_kind); bin_write_str(oss, m.content_type); bin_write_str(oss, m.created_at); bin_write_u64(oss, m.size_bytes); // Fetch raw data from cluster (per-media key) std::vector<uint8_t> raw; const_cast<Cluster&>(cluster_).fetch("media:" + m.id, raw); if (m.size_bytes > 0) { // Write actual fetched size — not m.size_bytes — so the // header always matches the data that follows. If the // fetch failed the entry gets size 0 (metadata preserved, // no corrupt zero-padding). bin_write_u64(oss, static_cast<std::uint64_t>(raw.size())); if (!raw.empty()) { // Write exactly size_bytes to match the header. // If the fetched data differs in length (e.g. degraded // cluster), truncate or pad to maintain format integrity. auto write_len = std::min<std::uint64_t>(raw.size(), m.size_bytes); oss.write(reinterpret_cast<const char*>(raw.data()), static_cast<std::streamsize>(write_len)); if (write_len < m.size_bytes) { std::vector<uint8_t> pad(m.size_bytes - write_len, 0); oss.write(reinterpret_cast<const char*>(pad.data()), static_cast<std::streamsize>(pad.size())); } } else { // Fetch failed — pad with zeros to maintain format integrity std::vector<uint8_t> zeros(m.size_bytes, 0); oss.write(reinterpret_cast<const char*>(zeros.data()), static_cast<std::streamsize>(zeros.size())); } static_cast<std::streamsize>(raw.size())); } } } Loading Loading
src/backend.cpp +8 −20 Original line number Diff line number Diff line Loading @@ -2913,30 +2913,18 @@ std::vector<std::uint8_t> ClusterMediaBackend::export_db_to_buffer_impl() const bin_write_str(oss, m.media_kind); bin_write_str(oss, m.content_type); bin_write_str(oss, m.created_at); bin_write_u64(oss, m.size_bytes); // Fetch raw data from cluster (per-media key) std::vector<uint8_t> raw; const_cast<Cluster&>(cluster_).fetch("media:" + m.id, raw); if (m.size_bytes > 0) { // Write actual fetched size — not m.size_bytes — so the // header always matches the data that follows. If the // fetch failed the entry gets size 0 (metadata preserved, // no corrupt zero-padding). bin_write_u64(oss, static_cast<std::uint64_t>(raw.size())); if (!raw.empty()) { // Write exactly size_bytes to match the header. // If the fetched data differs in length (e.g. degraded // cluster), truncate or pad to maintain format integrity. auto write_len = std::min<std::uint64_t>(raw.size(), m.size_bytes); oss.write(reinterpret_cast<const char*>(raw.data()), static_cast<std::streamsize>(write_len)); if (write_len < m.size_bytes) { std::vector<uint8_t> pad(m.size_bytes - write_len, 0); oss.write(reinterpret_cast<const char*>(pad.data()), static_cast<std::streamsize>(pad.size())); } } else { // Fetch failed — pad with zeros to maintain format integrity std::vector<uint8_t> zeros(m.size_bytes, 0); oss.write(reinterpret_cast<const char*>(zeros.data()), static_cast<std::streamsize>(zeros.size())); } static_cast<std::streamsize>(raw.size())); } } } Loading