Changeset 14293


Ignore:
Timestamp:
Jun 9, 2014, 2:53:04 AM (6 years ago)
Author:
jordan
Message:

(trunk, libT) #5517 when parsing a torrent's metainfo's path list, allow empty components because some .torrent files innocently have them. Update unit tests.

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/metainfo-test.c

    r14241 r14293  
    88 */
    99
     10#include "libtransmission-test.h"
     11
    1012#include "transmission.h"
    1113
    12 #include "libtransmission-test.h"
     14#include <errno.h>
    1315
    1416static int
    15 test1 (void)
     17test_magnet_link (void)
    1618{
    17     tr_info inf;
    18     tr_ctor * ctor;
    19     const char * magnet_link;
    20     tr_parse_result parse_result;
     19  tr_info inf;
     20  tr_ctor * ctor;
     21  const char * magnet_link;
     22  tr_parse_result parse_result;
    2123
    22     /* background info @ http://wiki.theory.org/BitTorrent_Magnet-URI_Webseeding */
    23     magnet_link = "magnet:?"
    24                   "xt=urn:btih:14FFE5DD23188FD5CB53A1D47F1289DB70ABF31E"
    25                   "&dn=ubuntu+12+04+1+desktop+32+bit"
    26                   "&tr=http%3A%2F%2Ftracker.publicbt.com%2Fannounce"
    27                   "&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80"
    28                   "&ws=http://transmissionbt.com ";
    29     ctor = tr_ctorNew (NULL);
    30     tr_ctorSetMetainfoFromMagnetLink (ctor, magnet_link);
    31     parse_result = tr_torrentParse (ctor, &inf);
    32     check_int_eq (inf.fileCount, 0); /* cos it's a magnet link */
    33     check_int_eq (parse_result, TR_PARSE_OK);
    34     check_int_eq (inf.trackerCount, 2);
    35     check_streq ("http://tracker.publicbt.com/announce", inf.trackers[0].announce);
    36     check_streq ("udp://tracker.publicbt.com:80", inf.trackers[1].announce);
    37     check_int_eq (inf.webseedCount, 1);
    38     check_streq ("http://transmissionbt.com", inf.webseeds[0]);
     24  /* background info @ http://wiki.theory.org/BitTorrent_Magnet-URI_Webseeding */
     25  magnet_link = "magnet:?"
     26                "xt=urn:btih:14FFE5DD23188FD5CB53A1D47F1289DB70ABF31E"
     27                "&dn=ubuntu+12+04+1+desktop+32+bit"
     28                "&tr=http%3A%2F%2Ftracker.publicbt.com%2Fannounce"
     29                "&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80"
     30                "&ws=http://transmissionbt.com ";
     31  ctor = tr_ctorNew (NULL);
     32  tr_ctorSetMetainfoFromMagnetLink (ctor, magnet_link);
     33  parse_result = tr_torrentParse (ctor, &inf);
     34  check_int_eq (inf.fileCount, 0); /* cos it's a magnet link */
     35  check_int_eq (parse_result, TR_PARSE_OK);
     36  check_int_eq (inf.trackerCount, 2);
     37  check_streq ("http://tracker.publicbt.com/announce", inf.trackers[0].announce);
     38  check_streq ("udp://tracker.publicbt.com:80", inf.trackers[1].announce);
     39  check_int_eq (inf.webseedCount, 1);
     40  check_streq ("http://transmissionbt.com", inf.webseeds[0]);
    3941
    40     /* cleanup */
    41     tr_metainfoFree (&inf);
    42     tr_ctorFree (ctor);
    43     return 0;
     42  /* cleanup */
     43  tr_metainfoFree (&inf);
     44  tr_ctorFree (ctor);
     45  return 0;
    4446}
    4547
    46 MAIN_SINGLE_TEST (test1)
     48#define BEFORE_PATH "d10:created by25:Transmission/2.82 (14160)13:creation datei1402280218e8:encoding5:UTF-84:infod5:filesld6:lengthi2e4:pathl"
     49#define AFTER_PATH "eed6:lengthi2e4:pathl5:b.txteee4:name3:foo12:piece lengthi32768e6:pieces20:ÞÉ`âM‘‹Šs¡Ã
     50;˺¬.åÂà7:privatei0eee"
     51
     52static int
     53test_metainfo (void)
     54{
     55  size_t i;
     56  const struct {
     57    int expected_benc_err;
     58    int expected_parse_result;
     59    const void * benc;
     60  } metainfo[] = {
     61    { 0,      TR_PARSE_OK,  BEFORE_PATH "5:a.txt"     AFTER_PATH },
     62
     63    /* allow empty components, but not =all= empty components, see bug #5517 */
     64    { 0,      TR_PARSE_OK,  BEFORE_PATH "0:5:a.txt"   AFTER_PATH },
     65    { 0,      TR_PARSE_ERR, BEFORE_PATH "0:0:"        AFTER_PATH },
     66
     67    /* don't allow path components in a filename */
     68    { 0,      TR_PARSE_ERR, BEFORE_PATH "7:a/a.txt"   AFTER_PATH },
     69
     70    /* fail on "." components */
     71    { 0,      TR_PARSE_ERR, BEFORE_PATH "1:.5:a.txt"  AFTER_PATH },
     72    { 0,      TR_PARSE_ERR, BEFORE_PATH "5:a.txt1:."  AFTER_PATH },
     73
     74    /* fail on ".." components */
     75    { 0,      TR_PARSE_ERR, BEFORE_PATH "2:..5:a.txt" AFTER_PATH },
     76    { 0,      TR_PARSE_ERR, BEFORE_PATH "5:a.txt2:.." AFTER_PATH },
     77
     78    /* fail on empty string */
     79    { EILSEQ, TR_PARSE_ERR, "" }
     80  };
     81
     82  tr_logSetLevel(0); /* yes, we already know these will generate errors, thank you... */
     83
     84
     85  for (i=0; i<(sizeof(metainfo) / sizeof(metainfo[0])); i++)
     86    {
     87      tr_ctor * ctor = tr_ctorNew (NULL);
     88      const int err = tr_ctorSetMetainfo (ctor, metainfo[i].benc, strlen(metainfo[i].benc));
     89      check_int_eq (metainfo[i].expected_benc_err, err);
     90      if (!err)
     91        {
     92          const tr_parse_result parse_result = tr_torrentParse (ctor, NULL);
     93          check_int_eq (metainfo[i].expected_parse_result, parse_result);
     94        }
     95      tr_ctorFree (ctor);
     96    }
     97
     98  return 0;
     99}
     100   
     101int
     102main (void)
     103{
     104  const testFunc tests[] = { test_magnet_link,
     105                             test_metainfo };
     106
     107  return runTests (tests, NUM_TESTS (tests));
     108}
     109
  • trunk/libtransmission/metainfo.c

    r14291 r14293  
    7777{
    7878  return (component == NULL)
    79       || (*component == '\0')
    8079      || (strpbrk (component, PATH_DELIMITER_CHARS) != NULL)
    8180      || (strcmp (component, ".") == 0)
     
    8786{
    8887  bool success = false;
     88  size_t root_len = 0;
    8989
    9090  *setme = NULL;
     
    100100      success = true;
    101101      evbuffer_drain (buf, evbuffer_get_length (buf));
    102       evbuffer_add (buf, root, strlen (root));
     102      root_len = strlen (root);
     103      evbuffer_add (buf, root, root_len);
    103104
    104105      for (i=0; i<n; i++)
     
    114115            }
    115116
     117          if (!*str)
     118            continue;
     119
    116120          evbuffer_add (buf, TR_PATH_DELIMITER_STR, 1);
    117121          evbuffer_add (buf, str, len);
    118122        }
     123    }
     124
     125  if (success && (evbuffer_get_length (buf) <= root_len))
     126    {
     127      success = false;
    119128    }
    120129
  • trunk/libtransmission/variant-benc.c

    r14241 r14293  
    249249    }
    250250
    251   if (!err)
    252     err = !top->type || !tr_ptrArrayEmpty(&stack);
     251  if (!err && (!top->type || !tr_ptrArrayEmpty(&stack)))
     252    err = EILSEQ;
    253253
    254254  if (!err && setme_end)
Note: See TracChangeset for help on using the changeset viewer.