From f29bb69612a528b7ca05adda14a7e63ac2c6dc32 Mon Sep 17 00:00:00 2001 From: arvidn Date: Wed, 10 Jan 2018 23:05:50 +0100 Subject: [PATCH 1/3] fix error handling of unsupported hard-links --- ChangeLog | 2 ++ src/file.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index c2bd5c25b..82868fdf5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,6 @@ + * fix error handling of unsupported hard-links + 1.1.6 release * deprecate save_encryption_settings (they are part of the normal settings) diff --git a/src/file.cpp b/src/file.cpp index 1374be743..a34c34902 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -568,7 +568,7 @@ namespace libtorrent // most errors are passed through, except for the ones that indicate that // hard links are not supported and require a copy. // TODO: 2 test this on a FAT volume to see what error we get! - if (errno != EMLINK || errno != EXDEV) + if (errno != EMLINK && errno != EXDEV) { // some error happened, report up to the caller ec.assign(errno, system_category()); From a9085db760694096c7bfcd50f234da10631cd720 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sat, 13 Jan 2018 14:36:13 +0100 Subject: [PATCH 2/3] fix error handling of merkle torrents --- ChangeLog | 1 + src/torrent_info.cpp | 11 +++++++++-- test/Makefile.am | 1 + test/test_torrent_info.cpp | 1 + test/test_torrents/invalid_merkle.torrent | 1 + 5 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 test/test_torrents/invalid_merkle.torrent diff --git a/ChangeLog b/ChangeLog index 82868fdf5..fe3b3960e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ + * fix error handling of some merkle torrents * fix error handling of unsupported hard-links 1.1.6 release diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index 8deb076af..ed7cb1383 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -1258,8 +1258,15 @@ namespace libtorrent m_files.set_piece_length(0); return false; } - int num_leafs = merkle_num_leafs(files.num_pieces()); - int num_nodes = merkle_num_nodes(num_leafs); + if (files.num_pieces() <= 0) + { + ec = errors::no_files_in_torrent; + // mark the torrent as invalid + m_files.set_piece_length(0); + return false; + } + int const num_leafs = merkle_num_leafs(files.num_pieces()); + int const num_nodes = merkle_num_nodes(num_leafs); if (num_nodes - num_leafs >= (2<<24)) { ec = errors::too_many_pieces_in_torrent; diff --git a/test/Makefile.am b/test/Makefile.am index 7aab670e1..f59eb55d3 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -70,6 +70,7 @@ EXTRA_DIST = Jamfile \ test_torrents/httpseed.torrent \ test_torrents/invalid_file_size.torrent \ test_torrents/invalid_info.torrent \ + test_torrents/invalid_merkle.torrent \ test_torrents/invalid_name.torrent \ test_torrents/invalid_name2.torrent \ test_torrents/invalid_name3.torrent \ diff --git a/test/test_torrent_info.cpp b/test/test_torrent_info.cpp index 37ce96379..fc0847118 100644 --- a/test/test_torrent_info.cpp +++ b/test/test_torrent_info.cpp @@ -161,6 +161,7 @@ test_failing_torrent_t test_error_torrents[] = { "unaligned_pieces.torrent", errors::torrent_invalid_hashes }, { "invalid_root_hash.torrent", errors::torrent_invalid_hashes }, { "invalid_root_hash2.torrent", errors::torrent_missing_pieces }, + { "invalid_merkle.torrent", errors::no_files_in_torrent}, { "invalid_file_size.torrent", errors::torrent_invalid_length }, { "invalid_symlink.torrent", errors::torrent_invalid_name }, }; diff --git a/test/test_torrents/invalid_merkle.torrent b/test/test_torrents/invalid_merkle.torrent new file mode 100644 index 000000000..ec555de9d --- /dev/null +++ b/test/test_torrents/invalid_merkle.torrent @@ -0,0 +1 @@ +d10:cion datei15992e4:infod6:lengthi000e4:name4:temp12:piece lengthi12e9:root hash20:‚ž¼Œ&¾ÇJW›}ÜA4u,·¼‘‡ee From a67eb2f059a6e6733cddf8e1941769b19b0c541b Mon Sep 17 00:00:00 2001 From: arvidn Date: Sat, 13 Jan 2018 15:57:14 +0100 Subject: [PATCH 3/3] fix tracker connection bind issue for IPv6 trackers --- ChangeLog | 1 + src/session_impl.cpp | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index fe3b3960e..9173233c0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ + * fix tracker connection bind issue for IPv6 trackers * fix error handling of some merkle torrents * fix error handling of unsupported hard-links diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 3922c65e8..ba3aa6816 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -1332,7 +1332,11 @@ namespace aux { } #endif - if (!req.bind_ip) req.bind_ip = m_listen_interface.address(); + if (!req.bind_ip + && m_listen_interface.address() != address_v4::any()) + { + req.bind_ip = m_listen_interface.address(); + } m_tracker_manager.queue_request(get_io_service(), req, c); }