From d2bde64e719efa290c7fe2e45734d10aa1e657f8 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 19 Jun 2008 11:28:34 +0000 Subject: [PATCH] makes sure a torrent doesn't have too many pieces than can be handled. Fixes #61 --- include/libtorrent/piece_picker.hpp | 4 ++++ src/torrent.cpp | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/include/libtorrent/piece_picker.hpp b/include/libtorrent/piece_picker.hpp index 4b9e6bcc5..bd0f862b6 100755 --- a/include/libtorrent/piece_picker.hpp +++ b/include/libtorrent/piece_picker.hpp @@ -475,6 +475,10 @@ namespace libtorrent // if this is set to true, it means update_pieces() // has to be called before accessing m_pieces. mutable bool m_dirty; + public: + + enum { max_pieces = piece_pos::we_have_index - 1 }; + }; inline int piece_picker::blocks_in_piece(int index) const diff --git a/src/torrent.cpp b/src/torrent.cpp index 8650ea42f..871e31c42 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -407,6 +407,13 @@ namespace libtorrent m_block_size = (std::min)(m_block_size, m_torrent_file->piece_length()); + if (m_torrent_file->num_pieces() + > piece_picker::max_pieces) + { + m_error = "too many pieces in torrent"; + pause(); + } + // the shared_from_this() will create an intentional // cycle of ownership, se the hpp file for description. m_owning_storage = new piece_manager(shared_from_this(), m_torrent_file