read_size_hint does not exceed read_message_max

Fixes #2879
This commit is contained in:
Mohammad Nejati authored and Mohammad Nejati committed 2024-06-06 00:49:08 +03:30
1 parent 4bff457ef7
commit 767397e0c1
5 files changed
+137 -4

No files matched your search

@@ -311,8 +311,9 @@ struct impl_base<true>
read_size_hint_pmd(
std::size_t initial_size,
bool rd_done,
std::uint64_t rd_msg_max,
std::uint64_t rd_remain,
detail::frame_header const& rd_fh) const
frame_header const& rd_fh) const
{
using beast::detail::clamp;
std::size_t result;
@@ -339,6 +340,9 @@ struct impl_base<true>
initial_size, clamp(rd_remain));
done:
BOOST_ASSERT(result != 0);
// Ensure offered size does not exceed rd_msg_max
if(rd_msg_max)
result = clamp(result, rd_msg_max);
return result;
}
};
@@ -461,6 +465,7 @@ struct impl_base<false>
read_size_hint_pmd(
std::size_t initial_size,
bool rd_done,
std::uint64_t rd_msg_max,
std::uint64_t rd_remain,
frame_header const& rd_fh) const
{
@@ -485,6 +490,9 @@ struct impl_base<false>
initial_size, clamp(rd_remain));
}
BOOST_ASSERT(result != 0);
// Ensure offered size does not exceed rd_msg_max
if(rd_msg_max)
result = clamp(result, rd_msg_max);
return result;
}
};
+1 -1
View File
@@ -986,7 +986,7 @@ read_some(
if(! limit)
limit = (std::numeric_limits<std::size_t>::max)();
auto const size =
clamp(read_size_hint(buffer), limit);
clamp(impl_->read_size_hint_db(buffer), limit);
BOOST_ASSERT(size > 0);
auto mb = beast::detail::dynamic_buffer_prepare(
buffer, size, ec, error::buffer_overflow);
@@ -133,7 +133,7 @@ read_size_hint(
std::size_t initial_size) const
{
return impl_->read_size_hint_pmd(
initial_size, impl_->rd_done,
initial_size, impl_->rd_done, impl_->rd_msg_max,
impl_->rd_remain, impl_->rd_fh);
}
@@ -300,7 +300,7 @@ struct stream<NextLayer, deflateSupported>::impl_type
if(initial_size == 0)
return 1; // buffer is full
return this->read_size_hint_pmd(
initial_size, rd_done, rd_remain, rd_fh);
initial_size, rd_done, rd_msg_max, rd_remain, rd_fh);
}
template<class DynamicBuffer>
@@ -886,6 +886,9 @@ parse_fh(
return false;
}
}
// The final size of a deflated frame is unknown. In certain cases,
// post-inflation, it might shrink and become <= rd_msg_max.
// Therefore, we will verify the size during the inflation process.
if(! this->rd_deflated())
{
if(rd_msg_max && beast::detail::sum_exceeds(