diff --git a/protobuf/echo/EchoErrorPolicy.cpp b/protobuf/echo/EchoErrorPolicy.cpp index 985c2e754..2024d8970 100644 --- a/protobuf/echo/EchoErrorPolicy.cpp +++ b/protobuf/echo/EchoErrorPolicy.cpp @@ -1,4 +1,5 @@ #include "protobuf/echo/EchoErrorPolicy.hpp" +#include namespace services { diff --git a/protobuf/echo/EchoErrorPolicy.hpp b/protobuf/echo/EchoErrorPolicy.hpp index 73af320f2..918d64f1a 100644 --- a/protobuf/echo/EchoErrorPolicy.hpp +++ b/protobuf/echo/EchoErrorPolicy.hpp @@ -1,14 +1,7 @@ #ifndef PROTOBUF_ECHO_ERROR_POLICY_HPP #define PROTOBUF_ECHO_ERROR_POLICY_HPP -#include "infra/stream/BufferingStreamReader.hpp" -#include "infra/util/BoundedDeque.hpp" -#include "infra/util/Compatibility.hpp" -#include "infra/util/Function.hpp" -#include "infra/util/Observer.hpp" -#include "infra/util/Optional.hpp" -#include "protobuf/echo/Proto.hpp" -#include "protobuf/echo/Serialization.hpp" +#include namespace services { diff --git a/protobuf/echo/ProtoMessageReceiver.cpp b/protobuf/echo/ProtoMessageReceiver.cpp index 6c814f137..8e15464a5 100644 --- a/protobuf/echo/ProtoMessageReceiver.cpp +++ b/protobuf/echo/ProtoMessageReceiver.cpp @@ -112,6 +112,8 @@ namespace services while (!stream.Empty()) { auto range = infra::ReinterpretCastMemoryRange(stream.ContiguousRange()); + stream.ErrorPolicy().ReportResult(range.size() <= value.max_size() - value.size()); + range.shrink_from_back_to(value.max_size() - value.size()); value.insert(value.end(), range.begin(), range.end()); } }); diff --git a/protobuf/echo/test/TestProtoMessageReceiver.cpp b/protobuf/echo/test/TestProtoMessageReceiver.cpp index 496bea458..f35774b1c 100644 --- a/protobuf/echo/test/TestProtoMessageReceiver.cpp +++ b/protobuf/echo/test/TestProtoMessageReceiver.cpp @@ -198,9 +198,21 @@ TEST(ProtoMessageReceiverTest, parse_bytes) infra::StdVectorInputStreamReader::WithStorage data(infra::inPlace, std::initializer_list{ 10, 2, 5, 6 }); receiver.Feed(data); + EXPECT_FALSE(receiver.Failed()); EXPECT_EQ((infra::BoundedVector::WithMaxSize<10>{ { 5, 6 } }), receiver.message.value); } +TEST(ProtoMessageReceiverTest, parse_bytes_too_long) +{ + services::ProtoMessageReceiver receiver; + + infra::StdVectorInputStreamReader::WithStorage data(infra::inPlace, std::initializer_list{ 10, 51, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1 }); + receiver.Feed(data); + + EXPECT_TRUE(receiver.Failed()); + EXPECT_EQ((infra::BoundedVector::WithMaxSize<50>{ { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } }), receiver.message.value); +} + TEST(ProtoMessageReceiverTest, parse_message) { services::ProtoMessageReceiver receiver;