From bc74013f983084fc658b2783ee00a53ad94742cf Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Thu, 25 Jul 2019 23:10:33 +0300 Subject: [PATCH] Fixed UBSan report in ProtobufWriter --- dbms/src/Formats/ProtobufWriter.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dbms/src/Formats/ProtobufWriter.cpp b/dbms/src/Formats/ProtobufWriter.cpp index bca3449cb59..fcaedcab2a0 100644 --- a/dbms/src/Formats/ProtobufWriter.cpp +++ b/dbms/src/Formats/ProtobufWriter.cpp @@ -141,7 +141,8 @@ void ProtobufWriter::SimpleWriter::endMessage() size_t size_of_message = buffer.size() - num_bytes_skipped; writeVarint(size_of_message, out); for (const auto & piece : pieces) - out.write(reinterpret_cast(&buffer[piece.start]), piece.end - piece.start); + if (piece.end > piece.start) + out.write(reinterpret_cast(&buffer[piece.start]), piece.end - piece.start); buffer.clear(); pieces.clear(); num_bytes_skipped = 0;