diff --git a/libtorrent/src/peer_connection.cpp b/libtorrent/src/peer_connection.cpp index 4cc5393e2..5ffca0da9 100755 --- a/libtorrent/src/peer_connection.cpp +++ b/libtorrent/src/peer_connection.cpp @@ -304,8 +304,8 @@ namespace libtorrent TORRENT_ASSERT(t1); boost::shared_ptr t2 = rhs.associated_torrent().lock(); TORRENT_ASSERT(t2); - if (!is_choked()) c1 -= t1->torrent_file().piece_length(); - if (!rhs.is_choked()) c2 -= t2->torrent_file().piece_length(); + if (!is_choked()) c1 -= (std::max)(t1->torrent_file().piece_length(), 256 * 1024); + if (!rhs.is_choked()) c2 -= (std::max)(t2->torrent_file().piece_length(), 256 * 1024); return c1 < c2; } diff --git a/libtorrent/src/piece_picker.cpp b/libtorrent/src/piece_picker.cpp index c1941a6ff..a16be1218 100755 --- a/libtorrent/src/piece_picker.cpp +++ b/libtorrent/src/piece_picker.cpp @@ -996,10 +996,6 @@ namespace libtorrent #ifdef TORRENT_PICKER_LOG print_pieces(); #endif - -#ifndef NDEBUG - check_invariant(); -#endif } void piece_picker::we_dont_have(int index) diff --git a/libtorrent/src/policy.cpp b/libtorrent/src/policy.cpp index 0304fc6d9..db9861373 100755 --- a/libtorrent/src/policy.cpp +++ b/libtorrent/src/policy.cpp @@ -338,8 +338,7 @@ namespace libtorrent piece_picker* p = 0; if (m_torrent->has_picker()) p = &m_torrent->picker(); - for (iterator i = m_peers.begin() - , end(m_peers.end()); i != end;) + for (iterator i = m_peers.begin(); i != m_peers.end();) { if ((ses.m_ip_filter.access(i->second.addr) & ip_filter::blocked) == 0) { diff --git a/libtorrent/src/torrent_info.cpp b/libtorrent/src/torrent_info.cpp index 603cd1a27..5f5b8fd76 100755 --- a/libtorrent/src/torrent_info.cpp +++ b/libtorrent/src/torrent_info.cpp @@ -309,6 +309,13 @@ namespace libtorrent int ret = load_file(filename, buf); if (ret < 0) return; + if (buf.empty()) +#ifndef BOOST_NO_EXCEPTIONS + throw invalid_torrent_file(); +#else + return; +#endif + lazy_entry e; lazy_bdecode(&buf[0], &buf[0] + buf.size(), e); std::string error;