From 0e6f766a578c3a5ac8dc5a6506ab53b037550f20 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 27 Jul 2007 01:50:26 +0000 Subject: [PATCH] gracefully fail when poison torrents containing no files, or zero byte files, are opened. --- libtransmission/metainfo.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/libtransmission/metainfo.c b/libtransmission/metainfo.c index 650ea6c0a..6179057cb 100644 --- a/libtransmission/metainfo.c +++ b/libtransmission/metainfo.c @@ -253,8 +253,6 @@ realparse( tr_info_t * inf, const uint8_t * buf, size_t size ) memcpy (inf->pieces[i].hash, &val->val.s.s[i*SHA_DIGEST_LENGTH], SHA_DIGEST_LENGTH); } - /* TODO add more tests so we don't crash on weird files */ - /* get file or top directory name */ val = tr_bencDictFindFirst( beInfo, "name.utf-8", "name", NULL ); if( parseFiles( inf, tr_bencDictFindFirst( beInfo, @@ -265,6 +263,22 @@ realparse( tr_info_t * inf, const uint8_t * buf, size_t size ) goto fail; } + if( !inf->fileCount ) + { + tr_err( "Torrent has no files." ); + goto fail; + } + for( i=0; ifileCount; ++i ) + { + if( !inf->files[i].length ) + { + tr_err("File #%d, \"%s\" is zero bytes long.", (i+1), inf->files[i].name ); + goto fail; + } + } + + /* TODO add more tests so we don't crash on weird files */ + if( (uint64_t) inf->pieceCount != ( inf->totalSize + inf->pieceSize - 1 ) / inf->pieceSize ) {