fix some warnings and integer overflow with torrents that are too big
This commit is contained in:
parent
c66f4cc62a
commit
68f05d6380
7
Jamfile
7
Jamfile
|
@ -393,12 +393,13 @@ rule tag ( name : type ? : property-set )
|
|||
feature ipv6 : on off : composite propagated link-incompatible ;
|
||||
feature.compose <ipv6>off : <define>TORRENT_USE_IPV6=0 ;
|
||||
|
||||
feature sanitize : off address bounds undefined thread rtc : composite propagated link-incompatible ;
|
||||
feature sanitize : off address memory bounds undefined thread rtc : composite propagated link-incompatible ;
|
||||
# sanitize is a clang and GCC feature
|
||||
feature.compose <sanitize>bounds : <cflags>-fsanitize=bounds <cflags>-fsanitize-undefined-trap-on-error <linkflags>-fsanitize=bounds <linkflags>-fsanitize-undefined-trap-on-error ;
|
||||
feature.compose <sanitize>undefined : <cflags>-fsanitize=undefined <linkflags>-fsanitize=undefined ;
|
||||
feature.compose <sanitize>bounds : <cflags>-fsanitize=bounds <cflags>-fsanitize-undefined-trap-on-error <linkflags>-fsanitize-undefined-trap-on-error ;
|
||||
feature.compose <sanitize>undefined : <cflags>-fsanitize=undefined <cflags>-fsanitize-undefined-trap-on-error <linkflags>-fsanitize=undefined <linkflags>-fsanitize-undefined-trap-on-error ;
|
||||
feature.compose <sanitize>thread : <cflags>-fsanitize=thread <linkflags>-fsanitize=thread ;
|
||||
feature.compose <sanitize>address : <cflags>-fsanitize=address <linkflags>-fsanitize=address ;
|
||||
feature.compose <sanitize>memory : <cflags>-fsanitize=memory <linkflags>-fsanitize=memory ;
|
||||
# RTC (runtime check) is an msvc feature
|
||||
feature.compose <sanitize>rtc : <cflags>/RTCc <cflags>/RTCsu ;
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ extern char const* libtorrent_assert_log;
|
|||
#endif
|
||||
|
||||
#define TORRENT_ASSERT_FAIL() \
|
||||
assert_fail("<unconditional>", __LINE__, __FILE__, TORRENT_FUNCTION, 0, 0)
|
||||
assert_fail("<unconditional>", __LINE__, __FILE__, TORRENT_FUNCTION, nullptr, 0)
|
||||
|
||||
#else
|
||||
#include <cassert>
|
||||
|
|
|
@ -282,7 +282,7 @@ namespace aux {
|
|||
|
||||
void set_peer_info(torrent_peer* pi) override
|
||||
{
|
||||
TORRENT_ASSERT(m_peer_info == 0 || pi == 0 );
|
||||
TORRENT_ASSERT(m_peer_info == nullptr || pi == nullptr );
|
||||
TORRENT_ASSERT(pi != nullptr || m_disconnect_started);
|
||||
m_peer_info = pi;
|
||||
}
|
||||
|
|
|
@ -408,7 +408,7 @@ namespace libtorrent {
|
|||
|
||||
void check_peer_invariant(typed_bitfield<piece_index_t> const& have
|
||||
, torrent_peer const* p) const;
|
||||
void check_invariant(const torrent* t = 0) const;
|
||||
void check_invariant(const torrent* t = nullptr) const;
|
||||
#endif
|
||||
|
||||
// functor that compares indices on downloading_pieces
|
||||
|
|
|
@ -75,10 +75,10 @@ namespace libtorrent {
|
|||
#if TORRENT_USE_ASSERTS
|
||||
|
||||
#define TORRENT_PIECE_ASSERT(cond, piece) \
|
||||
do { if (!(cond)) { assert_print_piece(piece); assert_fail(#cond, __LINE__, __FILE__, TORRENT_FUNCTION, 0); } } TORRENT_WHILE_0
|
||||
do { if (!(cond)) { assert_print_piece(piece); assert_fail(#cond, __LINE__, __FILE__, TORRENT_FUNCTION, nullptr); } } TORRENT_WHILE_0
|
||||
|
||||
#define TORRENT_PIECE_ASSERT_FAIL(piece) \
|
||||
do { assert_print_piece(piece); assert_fail("<unconditional>", __LINE__, __FILE__, TORRENT_FUNCTION, 0); } TORRENT_WHILE_0
|
||||
do { assert_print_piece(piece); assert_fail("<unconditional>", __LINE__, __FILE__, TORRENT_FUNCTION, nullptr); } TORRENT_WHILE_0
|
||||
|
||||
#else
|
||||
#define TORRENT_PIECE_ASSERT(cond, piece) do {} TORRENT_WHILE_0
|
||||
|
|
|
@ -99,7 +99,7 @@ namespace libtorrent {
|
|||
static const char invalid_chars[] = "/\\";
|
||||
#endif
|
||||
if (c > 127) return false;
|
||||
return std::strchr(invalid_chars, static_cast<char>(c)) != NULL;
|
||||
return std::strchr(invalid_chars, static_cast<char>(c)) != nullptr;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
@ -1014,6 +1014,15 @@ namespace {
|
|||
return false;
|
||||
}
|
||||
|
||||
// we expect the piece hashes to be < 2 GB in size
|
||||
if (files.num_pieces() >= std::numeric_limits<int>::max() / 20)
|
||||
{
|
||||
ec = errors::too_many_pieces_in_torrent;
|
||||
// mark the torrent as invalid
|
||||
m_files.set_piece_length(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pieces)
|
||||
{
|
||||
if (pieces.string_length() != files.num_pieces() * 20)
|
||||
|
@ -1038,13 +1047,6 @@ namespace {
|
|||
m_files.set_piece_length(0);
|
||||
return false;
|
||||
}
|
||||
if (files.num_pieces() >= std::numeric_limits<int>::max() / 2)
|
||||
{
|
||||
ec = errors::too_many_pieces_in_torrent;
|
||||
// mark the torrent as invalid
|
||||
m_files.set_piece_length(0);
|
||||
return false;
|
||||
}
|
||||
int const num_leafs = merkle_num_leafs(files.num_pieces());
|
||||
int const num_nodes = merkle_num_nodes(num_leafs);
|
||||
m_merkle_first_leaf = num_nodes - num_leafs;
|
||||
|
|
|
@ -76,7 +76,7 @@ EXPORT lt::alert const* wait_for_alert(
|
|||
EXPORT void print_ses_rate(float time
|
||||
, lt::torrent_status const* st1
|
||||
, lt::torrent_status const* st2
|
||||
, lt::torrent_status const* st3 = NULL);
|
||||
, lt::torrent_status const* st3 = nullptr);
|
||||
|
||||
EXPORT bool print_alerts(lt::session& ses, char const* name
|
||||
, bool allow_no_torrents = false
|
||||
|
@ -96,7 +96,7 @@ EXPORT std::shared_ptr<lt::torrent_info> make_torrent(const int file_sizes[]
|
|||
EXPORT void create_random_files(std::string const& path, const int file_sizes[]
|
||||
, int num_files, libtorrent::file_storage* fs = nullptr);
|
||||
|
||||
EXPORT std::shared_ptr<lt::torrent_info> create_torrent(std::ostream* file = 0
|
||||
EXPORT std::shared_ptr<lt::torrent_info> create_torrent(std::ostream* file = nullptr
|
||||
, char const* name = "temporary", int piece_size = 16 * 1024, int num_pieces = 13
|
||||
, bool add_tracker = true, std::string ssl_certificate = "");
|
||||
|
||||
|
@ -106,9 +106,11 @@ EXPORT std::tuple<lt::torrent_handle
|
|||
setup_transfer(lt::session* ses1, lt::session* ses2
|
||||
, lt::session* ses3, bool clear_files, bool use_metadata_transfer = true
|
||||
, bool connect = true, std::string suffix = "", int piece_size = 16 * 1024
|
||||
, std::shared_ptr<lt::torrent_info>* torrent = 0, bool super_seeding = false
|
||||
, lt::add_torrent_params const* p = 0, bool stop_lsd = true, bool use_ssl_ports = false
|
||||
, std::shared_ptr<lt::torrent_info>* torrent2 = 0);
|
||||
, std::shared_ptr<lt::torrent_info>* torrent = nullptr
|
||||
, bool super_seeding = false
|
||||
, lt::add_torrent_params const* p = nullptr
|
||||
, bool stop_lsd = true, bool use_ssl_ports = false
|
||||
, std::shared_ptr<lt::torrent_info>* torrent2 = nullptr);
|
||||
|
||||
EXPORT int start_web_server(bool ssl = false, bool chunked = false
|
||||
, bool keepalive = true, int min_interval = 30);
|
||||
|
|
|
@ -153,6 +153,7 @@ test_failing_torrent_t test_error_torrents[] =
|
|||
{ "invalid_root_hash2.torrent", errors::torrent_missing_pieces },
|
||||
{ "invalid_file_size.torrent", errors::torrent_invalid_length },
|
||||
{ "invalid_symlink.torrent", errors::torrent_invalid_name },
|
||||
{ "many_pieces.torrent", errors::too_many_pieces_in_torrent },
|
||||
};
|
||||
|
||||
// TODO: test remap_files
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
d10:created by10:libtorrent13:creation datei1359599503e4:infod6:lengthi1759218597889e4:name4:temp12:piece lengthi16384e6:pieces20:‚ž¼Œ&¾ÇJW›}ÜA4u,·¼‘‡ee
|
Loading…
Reference in New Issue