fix assert when adding an empty file (as a torrent) (#729)

This commit is contained in:
Arvid Norberg 2016-05-14 13:24:29 -04:00
parent 6dcbeae8bb
commit 0d27a0acdd
3 changed files with 46 additions and 7 deletions

View File

@ -4818,6 +4818,12 @@ namespace aux {
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;

View File

@ -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;
@ -143,6 +144,22 @@ TORRENT_TEST(async_add_torrent_duplicate)
TEST_CHECK(!a->error);
}
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<torrent_info>("", 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)
{
@ -158,8 +175,6 @@ TORRENT_TEST(session_stats)
TEST_EQUAL(stats[i].value_index, i);
}
}
#if __cplusplus >= 201103L
template <typename Set, typename Save, typename Default, typename Load>
void test_save_restore(Set setup, Save s, Default d, Load l)
{
@ -260,5 +275,3 @@ TORRENT_TEST(save_restore_state_load_filter)
});
}
#endif

View File

@ -612,7 +612,7 @@ TORRENT_TEST(parse_torrents)
fprintf(stderr, "loading %s\n", test_torrents[i].file);
std::string filename = combine_path(combine_path(root_dir, "test_torrents")
, test_torrents[i].file);
boost::shared_ptr<torrent_info> ti(new torrent_info(filename, ec));
auto ti = boost::make_shared<torrent_info>(filename, ec);
TEST_CHECK(!ec);
if (ec) fprintf(stderr, " loading(\"%s\") -> failed %s\n", filename.c_str()
, ec.message().c_str());
@ -751,8 +751,8 @@ TORRENT_TEST(parse_torrents)
{
error_code ec;
fprintf(stderr, "loading %s\n", test_error_torrents[i].file);
boost::shared_ptr<torrent_info> ti(new torrent_info(combine_path(
combine_path(root_dir, "test_torrents"), test_error_torrents[i].file), ec));
auto ti = boost::make_shared<torrent_info>(combine_path(
combine_path(root_dir, "test_torrents"), test_error_torrents[i].file), ec);
fprintf(stderr, "E: \"%s\"\nexpected: \"%s\"\n", ec.message().c_str()
, test_error_torrents[i].error.message().c_str());
TEST_CHECK(ec.message() == test_error_torrents[i].error.message());
@ -854,6 +854,26 @@ TORRENT_TEST(resolve_duplicates)
test_resolve_duplicates(i);
}
TORRENT_TEST(empty_file)
{
error_code ec;
auto ti = boost::make_shared<torrent_info>("", 0, ec);
TEST_CHECK(ec);
}
TORRENT_TEST(empty_file2)
{
try
{
auto ti = boost::make_shared<torrent_info>("", 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;