diff --git a/src/blob_serializer_deserializer-inl.h b/src/blob_serializer_deserializer-inl.h index 1d1204a96e6101..f47a1e0cdf8a44 100644 --- a/src/blob_serializer_deserializer-inl.h +++ b/src/blob_serializer_deserializer-inl.h @@ -139,6 +139,11 @@ std::string_view BlobDeserializer::ReadStringView(StringLogMode mode) { size_t length = ReadArithmetic(); Debug("ReadStringView(), length=%zu: ", length); + if (length == 0) { + Debug("ReadStringView() read an empty view\n"); + return std::string_view(); + } + std::string_view result(sink.data() + read_total, length); Debug("%p, read %zu bytes", result.data(), result.size()); if (mode == StringLogMode::kAddressAndContent) { @@ -269,6 +274,10 @@ size_t BlobSerializer::WriteStringView(std::string_view data, size_t written_total = WriteArithmetic(data.size()); size_t length = data.size(); + if (length == 0) { + Debug("WriteStringView() wrote an empty view\n"); + return written_total; + } sink.insert(sink.end(), data.data(), data.data() + length); written_total += length;