Skip to content

Commit

Permalink
src: fix reading empty string views in Blob[De]serializer
Browse files Browse the repository at this point in the history
The string writing/reading was intended for debugging info
in snapshot, which had a CHECK_GT(length, 0) check, it then
got repurposed for SEA resource writing/reading and turned
into a helper for string views, but was not updated to handle
empty views, causing occasional crash in the CI when the
read is protected. This patch fixes it.
  • Loading branch information
joyeecheung committed Mar 7, 2024
1 parent 2246cd9 commit f9d846f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/blob_serializer_deserializer-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ std::string_view BlobDeserializer<Impl>::ReadStringView(StringLogMode mode) {
size_t length = ReadArithmetic<size_t>();
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) {
Expand Down Expand Up @@ -269,6 +274,10 @@ size_t BlobSerializer<Impl>::WriteStringView(std::string_view data,
size_t written_total = WriteArithmetic<size_t>(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;

Expand Down

0 comments on commit f9d846f

Please sign in to comment.