support large info-sections in torrent_info
This commit is contained in:
parent
3462c061a7
commit
f5da27ba9e
|
@ -608,12 +608,12 @@ namespace libtorrent
|
||||||
// the hash that identifies this torrent
|
// the hash that identifies this torrent
|
||||||
sha1_hash m_info_hash;
|
sha1_hash m_info_hash;
|
||||||
|
|
||||||
|
// the number of bytes in m_info_section
|
||||||
|
boost::uint32_t m_info_section_size;
|
||||||
|
|
||||||
// the index to the first leaf. This is where the hash for the
|
// the index to the first leaf. This is where the hash for the
|
||||||
// first piece is stored
|
// first piece is stored
|
||||||
boost::uint32_t m_merkle_first_leaf;
|
boost::uint32_t m_merkle_first_leaf:24;
|
||||||
|
|
||||||
// the number of bytes in m_info_section
|
|
||||||
boost::uint32_t m_info_section_size:24;
|
|
||||||
|
|
||||||
// this is used when creating a torrent. If there's
|
// this is used when creating a torrent. If there's
|
||||||
// only one file there are cases where it's impossible
|
// only one file there are cases where it's impossible
|
||||||
|
|
|
@ -623,8 +623,8 @@ namespace libtorrent
|
||||||
, m_created_by(t.m_created_by)
|
, m_created_by(t.m_created_by)
|
||||||
, m_creation_date(t.m_creation_date)
|
, m_creation_date(t.m_creation_date)
|
||||||
, m_info_hash(t.m_info_hash)
|
, m_info_hash(t.m_info_hash)
|
||||||
, m_merkle_first_leaf(t.m_merkle_first_leaf)
|
|
||||||
, m_info_section_size(t.m_info_section_size)
|
, m_info_section_size(t.m_info_section_size)
|
||||||
|
, m_merkle_first_leaf(t.m_merkle_first_leaf)
|
||||||
, m_multifile(t.m_multifile)
|
, m_multifile(t.m_multifile)
|
||||||
, m_private(t.m_private)
|
, m_private(t.m_private)
|
||||||
, m_i2p(t.m_i2p)
|
, m_i2p(t.m_i2p)
|
||||||
|
@ -769,8 +769,8 @@ namespace libtorrent
|
||||||
, int flags)
|
, int flags)
|
||||||
: m_piece_hashes(0)
|
: m_piece_hashes(0)
|
||||||
, m_creation_date(0)
|
, m_creation_date(0)
|
||||||
, m_merkle_first_leaf(0)
|
|
||||||
, m_info_section_size(0)
|
, m_info_section_size(0)
|
||||||
|
, m_merkle_first_leaf(0)
|
||||||
, m_multifile(false)
|
, m_multifile(false)
|
||||||
, m_private(false)
|
, m_private(false)
|
||||||
, m_i2p(false)
|
, m_i2p(false)
|
||||||
|
@ -786,8 +786,8 @@ namespace libtorrent
|
||||||
torrent_info::torrent_info(lazy_entry const& torrent_file, int flags)
|
torrent_info::torrent_info(lazy_entry const& torrent_file, int flags)
|
||||||
: m_piece_hashes(0)
|
: m_piece_hashes(0)
|
||||||
, m_creation_date(0)
|
, m_creation_date(0)
|
||||||
, m_merkle_first_leaf(0)
|
|
||||||
, m_info_section_size(0)
|
, m_info_section_size(0)
|
||||||
|
, m_merkle_first_leaf(0)
|
||||||
, m_multifile(false)
|
, m_multifile(false)
|
||||||
, m_private(false)
|
, m_private(false)
|
||||||
, m_i2p(false)
|
, m_i2p(false)
|
||||||
|
@ -816,8 +816,8 @@ namespace libtorrent
|
||||||
torrent_info::torrent_info(entry const& torrent_file)
|
torrent_info::torrent_info(entry const& torrent_file)
|
||||||
: m_piece_hashes(0)
|
: m_piece_hashes(0)
|
||||||
, m_creation_date(0)
|
, m_creation_date(0)
|
||||||
, m_merkle_first_leaf(0)
|
|
||||||
, m_info_section_size(0)
|
, m_info_section_size(0)
|
||||||
|
, m_merkle_first_leaf(0)
|
||||||
, m_multifile(false)
|
, m_multifile(false)
|
||||||
, m_private(false)
|
, m_private(false)
|
||||||
, m_i2p(false)
|
, m_i2p(false)
|
||||||
|
@ -850,8 +850,8 @@ namespace libtorrent
|
||||||
torrent_info::torrent_info(bdecode_node const& torrent_file, int flags)
|
torrent_info::torrent_info(bdecode_node const& torrent_file, int flags)
|
||||||
: m_piece_hashes(0)
|
: m_piece_hashes(0)
|
||||||
, m_creation_date(0)
|
, m_creation_date(0)
|
||||||
, m_merkle_first_leaf(0)
|
|
||||||
, m_info_section_size(0)
|
, m_info_section_size(0)
|
||||||
|
, m_merkle_first_leaf(0)
|
||||||
, m_multifile(false)
|
, m_multifile(false)
|
||||||
, m_private(false)
|
, m_private(false)
|
||||||
, m_i2p(false)
|
, m_i2p(false)
|
||||||
|
@ -866,8 +866,8 @@ namespace libtorrent
|
||||||
torrent_info::torrent_info(char const* buffer, int size, int flags)
|
torrent_info::torrent_info(char const* buffer, int size, int flags)
|
||||||
: m_piece_hashes(0)
|
: m_piece_hashes(0)
|
||||||
, m_creation_date(0)
|
, m_creation_date(0)
|
||||||
, m_merkle_first_leaf(0)
|
|
||||||
, m_info_section_size(0)
|
, m_info_section_size(0)
|
||||||
|
, m_merkle_first_leaf(0)
|
||||||
, m_multifile(false)
|
, m_multifile(false)
|
||||||
, m_private(false)
|
, m_private(false)
|
||||||
, m_i2p(false)
|
, m_i2p(false)
|
||||||
|
@ -886,8 +886,8 @@ namespace libtorrent
|
||||||
torrent_info::torrent_info(std::string const& filename, int flags)
|
torrent_info::torrent_info(std::string const& filename, int flags)
|
||||||
: m_piece_hashes(0)
|
: m_piece_hashes(0)
|
||||||
, m_creation_date(0)
|
, m_creation_date(0)
|
||||||
, m_merkle_first_leaf(0)
|
|
||||||
, m_info_section_size(0)
|
, m_info_section_size(0)
|
||||||
|
, m_merkle_first_leaf(0)
|
||||||
, m_multifile(false)
|
, m_multifile(false)
|
||||||
, m_private(false)
|
, m_private(false)
|
||||||
, m_i2p(false)
|
, m_i2p(false)
|
||||||
|
@ -912,8 +912,8 @@ namespace libtorrent
|
||||||
torrent_info::torrent_info(std::wstring const& filename, int flags)
|
torrent_info::torrent_info(std::wstring const& filename, int flags)
|
||||||
: m_piece_hashes(0)
|
: m_piece_hashes(0)
|
||||||
, m_creation_date(0)
|
, m_creation_date(0)
|
||||||
, m_merkle_first_leaf(0)
|
|
||||||
, m_info_section_size(0)
|
, m_info_section_size(0)
|
||||||
|
, m_merkle_first_leaf(0)
|
||||||
, m_multifile(false)
|
, m_multifile(false)
|
||||||
, m_private(false)
|
, m_private(false)
|
||||||
, m_i2p(false)
|
, m_i2p(false)
|
||||||
|
@ -949,8 +949,8 @@ namespace libtorrent
|
||||||
, int flags)
|
, int flags)
|
||||||
: m_piece_hashes(0)
|
: m_piece_hashes(0)
|
||||||
, m_creation_date(0)
|
, m_creation_date(0)
|
||||||
, m_merkle_first_leaf(0)
|
|
||||||
, m_info_section_size(0)
|
, m_info_section_size(0)
|
||||||
|
, m_merkle_first_leaf(0)
|
||||||
, m_multifile(false)
|
, m_multifile(false)
|
||||||
, m_private(false)
|
, m_private(false)
|
||||||
, m_i2p(false)
|
, m_i2p(false)
|
||||||
|
@ -963,8 +963,8 @@ namespace libtorrent
|
||||||
torrent_info::torrent_info(char const* buffer, int size, error_code& ec, int flags)
|
torrent_info::torrent_info(char const* buffer, int size, error_code& ec, int flags)
|
||||||
: m_piece_hashes(0)
|
: m_piece_hashes(0)
|
||||||
, m_creation_date(0)
|
, m_creation_date(0)
|
||||||
, m_merkle_first_leaf(0)
|
|
||||||
, m_info_section_size(0)
|
, m_info_section_size(0)
|
||||||
|
, m_merkle_first_leaf(0)
|
||||||
, m_multifile(false)
|
, m_multifile(false)
|
||||||
, m_private(false)
|
, m_private(false)
|
||||||
, m_i2p(false)
|
, m_i2p(false)
|
||||||
|
@ -980,8 +980,8 @@ namespace libtorrent
|
||||||
torrent_info::torrent_info(std::string const& filename, error_code& ec, int flags)
|
torrent_info::torrent_info(std::string const& filename, error_code& ec, int flags)
|
||||||
: m_piece_hashes(0)
|
: m_piece_hashes(0)
|
||||||
, m_creation_date(0)
|
, m_creation_date(0)
|
||||||
, m_merkle_first_leaf(0)
|
|
||||||
, m_info_section_size(0)
|
, m_info_section_size(0)
|
||||||
|
, m_merkle_first_leaf(0)
|
||||||
, m_multifile(false)
|
, m_multifile(false)
|
||||||
, m_private(false)
|
, m_private(false)
|
||||||
, m_i2p(false)
|
, m_i2p(false)
|
||||||
|
@ -1004,8 +1004,8 @@ namespace libtorrent
|
||||||
, int flags)
|
, int flags)
|
||||||
: m_piece_hashes(0)
|
: m_piece_hashes(0)
|
||||||
, m_creation_date(0)
|
, m_creation_date(0)
|
||||||
, m_merkle_first_leaf(0)
|
|
||||||
, m_info_section_size(0)
|
, m_info_section_size(0)
|
||||||
|
, m_merkle_first_leaf(0)
|
||||||
, m_multifile(false)
|
, m_multifile(false)
|
||||||
, m_private(false)
|
, m_private(false)
|
||||||
, m_i2p(false)
|
, m_i2p(false)
|
||||||
|
@ -1034,8 +1034,8 @@ namespace libtorrent
|
||||||
: m_piece_hashes(0)
|
: m_piece_hashes(0)
|
||||||
, m_creation_date(time(0))
|
, m_creation_date(time(0))
|
||||||
, m_info_hash(info_hash)
|
, m_info_hash(info_hash)
|
||||||
, m_merkle_first_leaf(0)
|
|
||||||
, m_info_section_size(0)
|
, m_info_section_size(0)
|
||||||
|
, m_merkle_first_leaf(0)
|
||||||
, m_multifile(false)
|
, m_multifile(false)
|
||||||
, m_private(false)
|
, m_private(false)
|
||||||
, m_i2p(false)
|
, m_i2p(false)
|
||||||
|
@ -1152,8 +1152,7 @@ namespace libtorrent
|
||||||
h.update(section.first, section.second);
|
h.update(section.first, section.second);
|
||||||
m_info_hash = h.final();
|
m_info_hash = h.final();
|
||||||
|
|
||||||
// the internal metadata size is only 24 bits
|
if (section.second >= UINT32_MAX)
|
||||||
if (section.second >= (2<<24))
|
|
||||||
{
|
{
|
||||||
ec = errors::metadata_too_large;
|
ec = errors::metadata_too_large;
|
||||||
return false;
|
return false;
|
||||||
|
@ -1251,6 +1250,11 @@ namespace libtorrent
|
||||||
}
|
}
|
||||||
int num_leafs = merkle_num_leafs(files.num_pieces());
|
int num_leafs = merkle_num_leafs(files.num_pieces());
|
||||||
int num_nodes = merkle_num_nodes(num_leafs);
|
int num_nodes = merkle_num_nodes(num_leafs);
|
||||||
|
if (num_nodes - num_leafs >= (2<<24))
|
||||||
|
{
|
||||||
|
ec = errors::too_many_pieces_in_torrent;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
m_merkle_first_leaf = num_nodes - num_leafs;
|
m_merkle_first_leaf = num_nodes - num_leafs;
|
||||||
m_merkle_tree.resize(num_nodes);
|
m_merkle_tree.resize(num_nodes);
|
||||||
std::memset(&m_merkle_tree[0], 0, num_nodes * 20);
|
std::memset(&m_merkle_tree[0], 0, num_nodes * 20);
|
||||||
|
|
Loading…
Reference in New Issue