diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 6bfa31b1f..5f1bc81b6 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -4929,6 +4929,12 @@ retry: params.ti = t; } + if (params.ti && !params.ti->is_valid()) + { + ec = errors::no_metadata; + return ptr_t(); + } + if (params.ti && params.ti->is_valid() && params.ti->num_files() == 0) { ec = errors::no_files_in_torrent; diff --git a/test/test_session.cpp b/test/test_session.cpp index 2c6e4d745..e5632d7b2 100644 --- a/test/test_session.cpp +++ b/test/test_session.cpp @@ -40,6 +40,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/performance_counters.hpp" #include "libtorrent/bdecode.hpp" #include "libtorrent/bencode.hpp" +#include "libtorrent/torrent_info.hpp" using namespace libtorrent; namespace lt = libtorrent; @@ -59,7 +60,6 @@ TORRENT_TEST(session) // verify that we get the appropriate performance warning because // we're allowing a larger queue than we have cache. - alert const* a; for (;;) { @@ -93,6 +93,23 @@ TORRENT_TEST(session) // the session object } +TORRENT_TEST(load_empty_file) +{ + settings_pack p; + p.set_int(settings_pack::alert_mask, ~0); + lt::session ses(p); + + add_torrent_params atp; + error_code ignore_errors; + atp.ti = boost::make_shared("", 0, ignore_errors); + atp.save_path = "."; + error_code ec; + torrent_handle h = ses.add_torrent(atp, ec); + + TEST_CHECK(!h.is_valid()); + TEST_CHECK(ec == error_code(errors::no_metadata)) +} + TORRENT_TEST(session_stats) { std::vector stats = session_stats_metrics(); @@ -107,6 +124,7 @@ TORRENT_TEST(session_stats) TEST_EQUAL(stats[i].value_index, i); } } + #if __cplusplus >= 201103L template diff --git a/test/test_torrent_info.cpp b/test/test_torrent_info.cpp index a419d9b56..d43c296d2 100644 --- a/test/test_torrent_info.cpp +++ b/test/test_torrent_info.cpp @@ -854,6 +854,26 @@ TORRENT_TEST(resolve_duplicates) test_resolve_duplicates(i); } +TORRENT_TEST(empty_file) +{ + error_code ec; + boost::shared_ptr ti = boost::make_shared("", 0, ec); + TEST_CHECK(ec); +} + +TORRENT_TEST(empty_file2) +{ + try + { + boost::shared_ptr ti = boost::make_shared("", 0); + TEST_ERROR("expected exception thrown"); + } + catch (libtorrent_exception& e) + { + printf("Expected error: %s\n", e.error().message().c_str()); + } +} + TORRENT_TEST(copy) { using namespace libtorrent;