saturate failed-bytes and redundant-bytes counters in torrent object, rather than asserting on overflow. This happens in the fuzzer, which keeps a torrent open for the entire run, causing it to max out redundant bytes

This commit is contained in:
arvidn 2019-07-29 14:51:44 -07:00 committed by Arvid Norberg
parent 8e23f9cc92
commit c9f953f487
1 changed files with 13 additions and 5 deletions

View File

@ -10835,11 +10835,15 @@ bool is_downloading_state(int const st)
{
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(b > 0);
TORRENT_ASSERT(m_total_redundant_bytes <= std::numeric_limits<std::int32_t>::max() - b);
m_total_redundant_bytes += b;
TORRENT_ASSERT(static_cast<int>(reason) >= 0);
TORRENT_ASSERT(static_cast<int>(reason) < static_cast<int>(waste_reason::max));
if (m_total_redundant_bytes <= std::numeric_limits<std::int32_t>::max() - b)
m_total_redundant_bytes += b;
else
m_total_redundant_bytes = std::numeric_limits<std::int32_t>::max();
// the stats counters are 64 bits, so we don't check for overflow there
m_stats_counters.inc_stats_counter(counters::recv_redundant_bytes, b);
m_stats_counters.inc_stats_counter(counters::waste_piece_timed_out + static_cast<int>(reason), b);
}
@ -10848,8 +10852,12 @@ bool is_downloading_state(int const st)
{
TORRENT_ASSERT(is_single_thread());
TORRENT_ASSERT(b > 0);
TORRENT_ASSERT(m_total_failed_bytes <= std::numeric_limits<std::int32_t>::max() - b);
m_total_failed_bytes += b;
if (m_total_failed_bytes <= std::numeric_limits<std::int32_t>::max() - b)
m_total_failed_bytes += b;
else
m_total_failed_bytes = std::numeric_limits<std::int32_t>::max();
// the stats counters are 64 bits, so we don't check for overflow there
m_stats_counters.inc_stats_counter(counters::recv_failed_bytes, b);
}