Added verification of the length of the protobuff message

This commit is contained in:
Nik 2019-07-18 15:58:03 +04:00
parent ff8ae637ca
commit 514851f0f8
2 changed files with 20 additions and 2 deletions

View File

@ -67,7 +67,9 @@ bool ProtobufReader::SimpleReader::startMessage()
if (unlikely(in.eof())) if (unlikely(in.eof()))
return false; return false;
size_t size_of_message = readVarint(); size_t size_of_message = readVarint();
current_message_end = cursor + size_of_message; if(size_of_message == 0)
unknownFormat();
current_message_end = root_message_end = cursor + size_of_message;
} }
else else
{ {
@ -375,6 +377,10 @@ void ProtobufReader::SimpleReader::ignoreGroup()
} }
} }
[[noreturn]] void ProtobufReader::SimpleReader::throwUnknownFormat() const
{
unknownFormat();
}
// Implementation for a converter from any protobuf field type to any DB data type. // Implementation for a converter from any protobuf field type to any DB data type.
class ProtobufReader::ConverterBaseImpl : public ProtobufReader::IConverter class ProtobufReader::ConverterBaseImpl : public ProtobufReader::IConverter

View File

@ -97,7 +97,15 @@ private:
bool readUInt(UInt64 & value); bool readUInt(UInt64 & value);
template<typename T> bool readFixed(T & value); template<typename T> bool readFixed(T & value);
bool readStringInto(PaddedPODArray<UInt8> & str); bool readStringInto(PaddedPODArray<UInt8> & str);
bool ALWAYS_INLINE maybeCanReadValue() const { return field_end != REACHED_END; } bool ALWAYS_INLINE maybeCanReadValue() const
{
if (field_end == REACHED_END)
return false;
if (cursor < root_message_end)
return true;
throwUnknownFormat();
}
private: private:
void readBinary(void* data, size_t size); void readBinary(void* data, size_t size);
@ -119,6 +127,8 @@ private:
void ignoreVarint(); void ignoreVarint();
void ignoreGroup(); void ignoreGroup();
[[noreturn]] void throwUnknownFormat() const;
static constexpr UInt64 REACHED_END = 0; static constexpr UInt64 REACHED_END = 0;
ReadBuffer & in; ReadBuffer & in;
@ -126,6 +136,8 @@ private:
std::vector<UInt64> parent_message_ends; std::vector<UInt64> parent_message_ends;
UInt64 current_message_end; UInt64 current_message_end;
UInt64 field_end; UInt64 field_end;
UInt64 root_message_end;
}; };
class IConverter class IConverter