Added assert for total_size in create_torrent (#636)

This commit is contained in:
Alden Torres 2016-04-22 13:51:06 -04:00 committed by Arvid Norberg
parent 3c40cacd5b
commit 6171c911a0
4 changed files with 24 additions and 8 deletions

View File

@ -34,12 +34,10 @@ POSSIBILITY OF SUCH DAMAGE.
#define TORRENT_CREATE_TORRENT_HPP_INCLUDED #define TORRENT_CREATE_TORRENT_HPP_INCLUDED
#include "libtorrent/bencode.hpp" #include "libtorrent/bencode.hpp"
#include "libtorrent/peer_id.hpp"
#include "libtorrent/file_storage.hpp" #include "libtorrent/file_storage.hpp"
#include "libtorrent/config.hpp" #include "libtorrent/config.hpp"
#include "libtorrent/storage.hpp" #include "libtorrent/storage.hpp"
#include "libtorrent/hasher.hpp" #include "libtorrent/hasher.hpp"
#include "libtorrent/utf8.hpp"
#include "libtorrent/file.hpp" // for combine_path etc. #include "libtorrent/file.hpp" // for combine_path etc.
#include "libtorrent/aux_/disable_warnings_push.hpp" #include "libtorrent/aux_/disable_warnings_push.hpp"

View File

@ -57,7 +57,7 @@ namespace libtorrent
{ {
// libtorrent uses boost.system's ``error_code`` class to represent // libtorrent uses boost.system's ``error_code`` class to represent
// errors. libtorrent has its own error category // errors. libtorrent has its own error category
// get_libtorrent_category() whith the error codes defined by // get_libtorrent_category() with the error codes defined by
// error_code_enum. // error_code_enum.
enum error_code_enum enum error_code_enum
{ {
@ -111,7 +111,7 @@ namespace libtorrent
invalid_entry_type, invalid_entry_type,
// The specified URI does not contain a valid info-hash // The specified URI does not contain a valid info-hash
missing_info_hash_in_uri, missing_info_hash_in_uri,
// One of the files in the torrent was unexpectadly small. This // One of the files in the torrent was unexpectedly small. This
// might be caused by files being changed by an external process // might be caused by files being changed by an external process
file_too_short, file_too_short,
// The URL used an unknown protocol. Currently ``http`` and // The URL used an unknown protocol. Currently ``http`` and
@ -122,7 +122,7 @@ namespace libtorrent
url_parse_error, url_parse_error,
// The peer sent a 'piece' message of length 0 // The peer sent a 'piece' message of length 0
peer_sent_empty_piece, peer_sent_empty_piece,
// A bencoded structure was currupt and failed to be parsed // A bencoded structure was corrupt and failed to be parsed
parse_failed, parse_failed,
// The fast resume file was missing or had an invalid file version // The fast resume file was missing or had an invalid file version
// tag // tag
@ -216,7 +216,7 @@ namespace libtorrent
invalid_reject, invalid_reject,
// The peer sent an invalid allow fast-message // The peer sent an invalid allow fast-message
invalid_allow_fast, invalid_allow_fast,
// The peer sent an invalid extesion message ID // The peer sent an invalid extension message ID
invalid_extended, invalid_extended,
// The peer sent an invalid message ID // The peer sent an invalid message ID
invalid_message, invalid_message,
@ -260,7 +260,7 @@ namespace libtorrent
// The web seed redirected to a path that no longer matches the // The web seed redirected to a path that no longer matches the
// .torrent directory structure // .torrent directory structure
invalid_redirection, invalid_redirection,
// The connection was closed becaused it redirected to a different // The connection was closed because it redirected to a different
// URL // URL
redirecting, redirecting,
// The HTTP range header is invalid // The HTTP range header is invalid
@ -314,7 +314,7 @@ namespace libtorrent
// This happens for magnet links before they have downloaded the // This happens for magnet links before they have downloaded the
// metadata, and also torrents added by URL. // metadata, and also torrents added by URL.
no_metadata, no_metadata,
// The peer sent an invalid ``dont_have`` message. The dont have // The peer sent an invalid ``dont_have`` message. The don't have
// message is an extension to allow peers to advertise that the // message is an extension to allow peers to advertise that the
// no longer has a piece they previously had. // no longer has a piece they previously had.
invalid_dont_have, invalid_dont_have,

View File

@ -31,6 +31,7 @@ POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "libtorrent/create_torrent.hpp" #include "libtorrent/create_torrent.hpp"
#include "libtorrent/utf8.hpp"
#include "libtorrent/file_pool.hpp" #include "libtorrent/file_pool.hpp"
#include "libtorrent/storage.hpp" #include "libtorrent/storage.hpp"
#include "libtorrent/aux_/escape_string.hpp" // for convert_to_wstring #include "libtorrent/aux_/escape_string.hpp" // for convert_to_wstring
@ -262,6 +263,12 @@ namespace libtorrent
return; return;
} }
if (t.files().total_size() == 0)
{
ec = error_code(errors::torrent_invalid_length, get_libtorrent_category());
return;
}
// dummy torrent object pointer // dummy torrent object pointer
boost::shared_ptr<char> dummy; boost::shared_ptr<char> dummy;
counters cnt; counters cnt;

View File

@ -261,7 +261,18 @@ TORRENT_TEST(torrent)
boost::shared_ptr<torrent_info> info(boost::make_shared<torrent_info>(&tmp[0], tmp.size(), boost::ref(ec), 0)); boost::shared_ptr<torrent_info> info(boost::make_shared<torrent_info>(&tmp[0], tmp.size(), boost::ref(ec), 0));
test_running_torrent(info, 0); test_running_torrent(info, 0);
} }
}
TORRENT_TEST(torrent_total_size_zero)
{
file_storage fs;
fs.add_file("test_torrent_dir2/tmp1", 0);
libtorrent::create_torrent t(fs);
error_code ec;
set_piece_hashes(t, ".", ec);
TEST_CHECK(ec);
} }