forked from premiere/premiere-libtorrent
fix integer overflow in alert_manager
This commit is contained in:
parent
c55bc7dd42
commit
95cfc16bca
2
Jamfile
2
Jamfile
|
@ -421,7 +421,7 @@ feature.compose <ipv6>off : <define>TORRENT_USE_IPV6=0 ;
|
|||
|
||||
feature sanitize : off address undefined thread rtc : composite propagated link-incompatible ;
|
||||
# sanitize is a clang and GCC feature
|
||||
feature.compose <sanitize>undefined : <cflags>-fsanitize=undefined <linkflags>-fsanitize=undefined ;
|
||||
feature.compose <sanitize>undefined : <cflags>-fsanitize=undefined <cflags>-fsanitize-undefined-trap-on-error <linkflags>-fsanitize=undefined ;
|
||||
feature.compose <sanitize>thread : <cflags>-fsanitize=thread <linkflags>-fsanitize=thread ;
|
||||
feature.compose <sanitize>address : <cflags>-fsanitize=address <linkflags>-fsanitize=address ;
|
||||
# RTC (runtime check) is an msvc feature
|
||||
|
|
|
@ -93,8 +93,8 @@ namespace libtorrent {
|
|||
// don't add more than this number of alerts, unless it's a
|
||||
// high priority alert, in which case we try harder to deliver it
|
||||
// for high priority alerts, double the upper limit
|
||||
if (m_alerts[m_generation].size() >= m_queue_size_limit
|
||||
* (1 + T::priority))
|
||||
if (m_alerts[m_generation].size() / (1 + T::priority)
|
||||
>= m_queue_size_limit)
|
||||
return;
|
||||
|
||||
T alert(m_allocations[m_generation], std::forward<Args>(args)...);
|
||||
|
@ -118,8 +118,8 @@ namespace libtorrent {
|
|||
bool should_post() const
|
||||
{
|
||||
recursive_mutex::scoped_lock lock(m_mutex);
|
||||
if (m_alerts[m_generation].size() >= m_queue_size_limit
|
||||
* (1 + T::priority))
|
||||
if (m_alerts[m_generation].size() / (1 + T::priority)
|
||||
>= m_queue_size_limit)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -37,8 +37,8 @@
|
|||
// don't add more than this number of alerts, unless it's a
|
||||
// high priority alert, in which case we try harder to deliver it
|
||||
// for high priority alerts, double the upper limit
|
||||
if (m_alerts[m_generation].size() >= m_queue_size_limit
|
||||
* (1 + T::priority))
|
||||
if (m_alerts[m_generation].size() / (1 + T::priority)
|
||||
>= m_queue_size_limit)
|
||||
return;
|
||||
|
||||
T alert(m_allocations[m_generation]
|
||||
|
|
|
@ -81,6 +81,26 @@ TORRENT_TEST(limit)
|
|||
TEST_EQUAL(alerts.size(), 200);
|
||||
}
|
||||
|
||||
TORRENT_TEST(limit_int_max)
|
||||
{
|
||||
int const inf = std::numeric_limits<int>::max();
|
||||
alert_manager mgr(inf, 0xffffffff);
|
||||
|
||||
TEST_EQUAL(mgr.alert_queue_size_limit(), inf);
|
||||
|
||||
for (int i = 0; i < 600; ++i)
|
||||
mgr.emplace_alert<piece_finished_alert>(torrent_handle(), i);
|
||||
|
||||
for (int i = 0; i < 600; ++i)
|
||||
mgr.emplace_alert<torrent_removed_alert>(torrent_handle(), sha1_hash());
|
||||
|
||||
std::vector<alert*> alerts;
|
||||
int num_resume;
|
||||
mgr.get_all(alerts, num_resume);
|
||||
|
||||
TEST_EQUAL(alerts.size(), 1200);
|
||||
}
|
||||
|
||||
TORRENT_TEST(priority_limit)
|
||||
{
|
||||
alert_manager mgr(100, 0xffffffff);
|
||||
|
|
Loading…
Reference in New Issue