Cap the output stream package size to kMaxAllowedReadBytes, which is 1048576

PiperOrigin-RevId: 459622727
This commit is contained in:
hai007
2022-07-07 16:00:19 -07:00
committed by Copybara-Service
parent c27ac64bb9
commit 0a7f68f382
@@ -223,8 +223,15 @@ Exception BaseEndpointChannel::Write(const ByteArray& data) {
}
}
size_t data_size = data_to_write->size();
if (data_size < 0 || data_size > kMaxAllowedReadBytes) {
NEARBY_LOGS(WARNING) << __func__ << ": Write an invalid number of bytes: "
<< data_size;
return {Exception::kIo};
}
Exception write_exception =
WriteInt(writer_, static_cast<std::int32_t>(data_to_write->size()));
WriteInt(writer_, static_cast<std::int32_t>(data_size));
if (write_exception.Raised()) {
NEARBY_LOGS(WARNING) << __func__ << ": Failed to write header: "
<< write_exception.value;