forked from premiere/premiere-libtorrent
fixed error handling in torrent_info constructor
This commit is contained in:
parent
99d2c4eea8
commit
6663f527da
|
@ -72,6 +72,7 @@
|
||||||
incoming connection
|
incoming connection
|
||||||
* added more detailed instrumentation of the disk I/O thread
|
* added more detailed instrumentation of the disk I/O thread
|
||||||
|
|
||||||
|
* fixed error handling in torrent_info constructor
|
||||||
* fixed bug in torrent_info::remap_files
|
* fixed bug in torrent_info::remap_files
|
||||||
* fix python binding for wait_for_alert
|
* fix python binding for wait_for_alert
|
||||||
* only apply privileged port filter to DHT-only peers
|
* only apply privileged port filter to DHT-only peers
|
||||||
|
|
|
@ -611,7 +611,7 @@ void add_torrent(libtorrent::session& ses
|
||||||
std::string filename = combine_path(save_path, t->name() + ".resume");
|
std::string filename = combine_path(save_path, t->name() + ".resume");
|
||||||
|
|
||||||
std::vector<char> buf;
|
std::vector<char> buf;
|
||||||
if (load_file(filename.c_str(), buf) == 0)
|
if (load_file(filename.c_str(), buf, ec) == 0)
|
||||||
p.resume_data = &buf;
|
p.resume_data = &buf;
|
||||||
|
|
||||||
p.ti = t;
|
p.ti = t;
|
||||||
|
@ -889,10 +889,10 @@ int main(int argc, char* argv[])
|
||||||
+ alert::stats_notification));
|
+ alert::stats_notification));
|
||||||
|
|
||||||
std::vector<char> in;
|
std::vector<char> in;
|
||||||
if (load_file(".ses_state", in) == 0)
|
error_code ec;
|
||||||
|
if (load_file(".ses_state", in, ec) == 0)
|
||||||
{
|
{
|
||||||
lazy_entry e;
|
lazy_entry e;
|
||||||
error_code ec;
|
|
||||||
if (lazy_bdecode(&in[0], &in[0] + in.size(), e, ec) == 0)
|
if (lazy_bdecode(&in[0], &in[0] + in.size(), e, ec) == 0)
|
||||||
ses.load_state(e);
|
ses.load_state(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,14 +59,14 @@ int main(int argc, char* argv[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
std::vector<char> buf(size);
|
std::vector<char> buf(size);
|
||||||
int ret = load_file(argv[1], buf, 40 * 1000000);
|
error_code ec;
|
||||||
|
int ret = load_file(argv[1], buf, ec, 40 * 1000000);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "failed to load file: %d\n", ret);
|
fprintf(stderr, "failed to load file: %s\n", ec.message().c_str());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
lazy_entry e;
|
lazy_entry e;
|
||||||
error_code ec;
|
|
||||||
int pos;
|
int pos;
|
||||||
printf("decoding. recursion limit: %d total item count limit: %d\n"
|
printf("decoding. recursion limit: %d total item count limit: %d\n"
|
||||||
, depth_limit, item_limit);
|
, depth_limit, item_limit);
|
||||||
|
|
|
@ -78,10 +78,10 @@ int main(int argc, char* argv[])
|
||||||
ses.set_settings(sett);
|
ses.set_settings(sett);
|
||||||
|
|
||||||
std::vector<char> in;
|
std::vector<char> in;
|
||||||
if (load_file(".ses_state", in) == 0)
|
error_code ec;
|
||||||
|
if (load_file(".ses_state", in, ec) == 0)
|
||||||
{
|
{
|
||||||
lazy_entry e;
|
lazy_entry e;
|
||||||
error_code ec;
|
|
||||||
if (lazy_bdecode(&in[0], &in[0] + in.size(), e, ec) == 0)
|
if (lazy_bdecode(&in[0], &in[0] + in.size(), e, ec) == 0)
|
||||||
ses.load_state(e);
|
ses.load_state(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,7 +222,7 @@ namespace libtorrent
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int TORRENT_EXPORT load_file(std::string const& filename
|
int TORRENT_EXPORT load_file(std::string const& filename
|
||||||
, std::vector<char>& v, int limit = 8000000);
|
, std::vector<char>& v, error_code& ec, int limit = 8000000);
|
||||||
|
|
||||||
class TORRENT_EXPORT torrent_info : public intrusive_ptr_base<torrent_info>
|
class TORRENT_EXPORT torrent_info : public intrusive_ptr_base<torrent_info>
|
||||||
{
|
{
|
||||||
|
|
|
@ -2305,6 +2305,7 @@ namespace libtorrent
|
||||||
lazy_entry const* rd = (lazy_entry const*)j.buffer;
|
lazy_entry const* rd = (lazy_entry const*)j.buffer;
|
||||||
TORRENT_ASSERT(rd != 0);
|
TORRENT_ASSERT(rd != 0);
|
||||||
ret = j.storage->check_fastresume(*rd, j.error);
|
ret = j.storage->check_fastresume(*rd, j.error);
|
||||||
|
test_error(j);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case disk_io_job::check_files:
|
case disk_io_job::check_files:
|
||||||
|
|
|
@ -517,6 +517,7 @@ namespace libtorrent
|
||||||
|
|
||||||
torrent_handle session::add_torrent(add_torrent_params const& params, error_code& ec)
|
torrent_handle session::add_torrent(add_torrent_params const& params, error_code& ec)
|
||||||
{
|
{
|
||||||
|
ec.clear();
|
||||||
if (string_begins_no_case("magnet:", params.url.c_str()))
|
if (string_begins_no_case("magnet:", params.url.c_str()))
|
||||||
{
|
{
|
||||||
add_torrent_params p(params);
|
add_torrent_params p(params);
|
||||||
|
|
|
@ -401,14 +401,18 @@ namespace libtorrent
|
||||||
return 1 << i;
|
return 1 << i;
|
||||||
}
|
}
|
||||||
|
|
||||||
int load_file(std::string const& filename, std::vector<char>& v, int limit)
|
int load_file(std::string const& filename, std::vector<char>& v, error_code& ec, int limit)
|
||||||
{
|
{
|
||||||
|
ec.clear();
|
||||||
file f;
|
file f;
|
||||||
error_code ec;
|
|
||||||
if (!f.open(filename, file::read_only, ec)) return -1;
|
if (!f.open(filename, file::read_only, ec)) return -1;
|
||||||
size_type s = f.get_size(ec);
|
size_type s = f.get_size(ec);
|
||||||
if (ec) return -1;
|
if (ec) return -1;
|
||||||
if (s > limit) return -2;
|
if (s > limit)
|
||||||
|
{
|
||||||
|
ec = error_code(errors::metadata_too_large, get_libtorrent_category());
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
v.resize(s);
|
v.resize(s);
|
||||||
if (s == 0) return 0;
|
if (s == 0) return 0;
|
||||||
file::iovec_t b = {&v[0], s};
|
file::iovec_t b = {&v[0], s};
|
||||||
|
@ -576,11 +580,11 @@ namespace libtorrent
|
||||||
, m_i2p(false)
|
, m_i2p(false)
|
||||||
{
|
{
|
||||||
std::vector<char> buf;
|
std::vector<char> buf;
|
||||||
int ret = load_file(filename, buf);
|
error_code ec;
|
||||||
if (ret < 0) return;
|
int ret = load_file(filename, buf, ec);
|
||||||
|
if (ret < 0) throw invalid_torrent_file(ec);
|
||||||
|
|
||||||
lazy_entry e;
|
lazy_entry e;
|
||||||
error_code ec;
|
|
||||||
if (buf.size() == 0 || lazy_bdecode(&buf[0], &buf[0] + buf.size(), e, ec) != 0)
|
if (buf.size() == 0 || lazy_bdecode(&buf[0], &buf[0] + buf.size(), e, ec) != 0)
|
||||||
throw invalid_torrent_file(ec);
|
throw invalid_torrent_file(ec);
|
||||||
|
|
||||||
|
@ -601,11 +605,11 @@ namespace libtorrent
|
||||||
std::vector<char> buf;
|
std::vector<char> buf;
|
||||||
std::string utf8;
|
std::string utf8;
|
||||||
wchar_utf8(filename, utf8);
|
wchar_utf8(filename, utf8);
|
||||||
int ret = load_file(utf8, buf);
|
error_code ec;
|
||||||
if (ret < 0) return;
|
int ret = load_file(utf8, buf, ec);
|
||||||
|
if (ret < 0) throw invalid_torrent_file(ec);
|
||||||
|
|
||||||
lazy_entry e;
|
lazy_entry e;
|
||||||
error_code ec;
|
|
||||||
if (buf.size() == 0 || lazy_bdecode(&buf[0], &buf[0] + buf.size(), e, ec) != 0)
|
if (buf.size() == 0 || lazy_bdecode(&buf[0], &buf[0] + buf.size(), e, ec) != 0)
|
||||||
throw invalid_torrent_file(ec);
|
throw invalid_torrent_file(ec);
|
||||||
|
|
||||||
|
@ -650,7 +654,7 @@ namespace libtorrent
|
||||||
, m_i2p(false)
|
, m_i2p(false)
|
||||||
{
|
{
|
||||||
std::vector<char> buf;
|
std::vector<char> buf;
|
||||||
int ret = load_file(filename, buf);
|
int ret = load_file(filename, buf, ec);
|
||||||
if (ret < 0) return;
|
if (ret < 0) return;
|
||||||
|
|
||||||
lazy_entry e;
|
lazy_entry e;
|
||||||
|
@ -671,7 +675,7 @@ namespace libtorrent
|
||||||
std::vector<char> buf;
|
std::vector<char> buf;
|
||||||
std::string utf8;
|
std::string utf8;
|
||||||
wchar_utf8(filename, utf8);
|
wchar_utf8(filename, utf8);
|
||||||
int ret = load_file(utf8, buf);
|
int ret = load_file(utf8, buf, ec);
|
||||||
if (ret < 0) return;
|
if (ret < 0) return;
|
||||||
|
|
||||||
lazy_entry e;
|
lazy_entry e;
|
||||||
|
|
|
@ -907,9 +907,9 @@ void web_server_thread(int* port, bool ssl, bool chunked)
|
||||||
int size = range_end - range_start + 1;
|
int size = range_end - range_start + 1;
|
||||||
boost::uint64_t off = idx * 64 * 1024 + range_start;
|
boost::uint64_t off = idx * 64 * 1024 + range_start;
|
||||||
std::vector<char> file_buf;
|
std::vector<char> file_buf;
|
||||||
int res = load_file("./tmp1_web_seed/seed", file_buf);
|
|
||||||
|
|
||||||
error_code ec;
|
error_code ec;
|
||||||
|
int res = load_file("./tmp1_web_seed/seed", file_buf, ec);
|
||||||
|
|
||||||
if (res == -1 || file_buf.empty())
|
if (res == -1 || file_buf.empty())
|
||||||
{
|
{
|
||||||
send_response(s, ec, 404, "Not Found", extra_header, 0);
|
send_response(s, ec, 404, "Not Found", extra_header, 0);
|
||||||
|
@ -931,7 +931,8 @@ void web_server_thread(int* port, bool ssl, bool chunked)
|
||||||
std::vector<char> file_buf;
|
std::vector<char> file_buf;
|
||||||
// remove the / from the path
|
// remove the / from the path
|
||||||
path = path.substr(1);
|
path = path.substr(1);
|
||||||
int res = load_file(path, file_buf);
|
error_code ec;
|
||||||
|
int res = load_file(path, file_buf, ec);
|
||||||
if (res == -1)
|
if (res == -1)
|
||||||
{
|
{
|
||||||
send_response(s, ec, 404, "Not Found", extra_header, 0);
|
send_response(s, ec, 404, "Not Found", extra_header, 0);
|
||||||
|
|
|
@ -180,7 +180,8 @@ void save_file(char const* filename, char const* data, int size)
|
||||||
sha1_hash file_hash(std::string const& name)
|
sha1_hash file_hash(std::string const& name)
|
||||||
{
|
{
|
||||||
std::vector<char> buf;
|
std::vector<char> buf;
|
||||||
load_file(name, buf);
|
error_code ec;
|
||||||
|
load_file(name, buf, ec);
|
||||||
if (buf.empty()) return sha1_hash(0);
|
if (buf.empty()) return sha1_hash(0);
|
||||||
hasher h(&buf[0], buf.size());
|
hasher h(&buf[0], buf.size());
|
||||||
return h.final();
|
return h.final();
|
||||||
|
|
Loading…
Reference in New Issue