diff --git a/ChangeLog b/ChangeLog index 576fd4753..abe66b596 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * handle invalid arguments to set_piece_deadline() * move_storage did not work for torrents without metadata * improve shutdown time by only announcing to trackers whose IP we know * fix python3 portability issue in python binding diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index de5528c79..ac8bb21fe 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -375,14 +375,14 @@ namespace libtorrent // deadline (and flags) of a piece can be changed by calling this // function again. // - // The ``flags`` parameter can be used to ask libtorrent to send an alert + // The ``flags`` parameter can be used to ask libtorrent to post an alert // once the piece has been downloaded, by passing alert_when_available. // When set, the read_piece_alert alert will be delivered, with the piece // data, when it's downloaded. // // If the piece is already downloaded when this call is made, nothing // happens, unless the alert_when_available flag is set, in which case it - // will do the same thing as calling read_piece() for ``index``. + // will have the same effect as calling read_piece() for ``index``. // // ``deadline`` is the number of milliseconds until this piece should be // completed. diff --git a/src/torrent.cpp b/src/torrent.cpp index 58f1e1d8d..e22807bb3 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -5235,7 +5235,13 @@ namespace libtorrent { INVARIANT_CHECK; - if (m_abort) + TORRENT_ASSERT_PRECOND(piece >= 0); + TORRENT_ASSERT_PRECOND(valid_metadata()); + TORRENT_ASSERT_PRECOND(valid_metadata() && piece < m_torrent_file->num_pieces()); + + if (m_abort || !valid_metadata() + || piece < 0 + || piece >= m_torrent_file->num_pieces()) { // failed if (flags & torrent_handle::alert_when_available)