From 33b03e1f8ed01d87565e93020c1cdd95f22eaa35 Mon Sep 17 00:00:00 2001 From: arvidn Date: Sun, 1 Oct 2017 05:15:27 +0200 Subject: [PATCH] improve handling of case where a torrent file has no files in it --- src/torrent_info.cpp | 7 +++++++ test/test_torrent_info.cpp | 1 + test/test_torrents/no_files.torrent | 1 + 3 files changed, 9 insertions(+) create mode 100644 test/test_torrents/no_files.torrent diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index d695a9a6c..c8fd9d5ad 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -1000,6 +1000,13 @@ namespace { } m_flags |= multifile; } + if (files.num_files() == 0) + { + ec = errors::no_files_in_torrent; + // mark the torrent as invalid + m_files.set_piece_length(0); + return false; + } TORRENT_ASSERT(!files.name().empty()); // extract SHA-1 hashes for all pieces diff --git a/test/test_torrent_info.cpp b/test/test_torrent_info.cpp index 9e2d861f4..8118ad793 100644 --- a/test/test_torrent_info.cpp +++ b/test/test_torrent_info.cpp @@ -155,6 +155,7 @@ test_failing_torrent_t test_error_torrents[] = { "invalid_file_size.torrent", errors::torrent_invalid_length }, { "invalid_symlink.torrent", errors::torrent_invalid_name }, { "many_pieces.torrent", errors::too_many_pieces_in_torrent }, + { "no_files.torrent", errors::no_files_in_torrent}, }; // TODO: test remap_files diff --git a/test/test_torrents/no_files.torrent b/test/test_torrents/no_files.torrent new file mode 100644 index 000000000..b27bab68d --- /dev/null +++ b/test/test_torrents/no_files.torrent @@ -0,0 +1 @@ +d10:created by10:libtorrent13:creation datei1359599503e4:infod5:filesle4:name4:temp12:piece lengthi16384e6:pieces20:‚ž¼Œ&¾ÇJW›}ÜA4u,·¼‘‡ee