[package] update libtorrent to r1093 (#5218)
[openwrt/svn-archive/archive.git] / libs / libtorrent / patches / 010-bencode_check_info_only.patch
1 # Limit the unordered bencode dictionary check to the info dictionary and all its elements.
2 Index: libtorrent/src/torrent/object.h
3 ===================================================================
4 --- libtorrent/src/torrent/object.h (revision 1093)
5 +++ libtorrent/src/torrent/object.h (working copy)
6 @@ -75,6 +75,8 @@
7 static const uint32_t mask_internal = 0xffff;
8 static const uint32_t mask_public = ~mask_internal;
9
10 + static const uint32_t flag_unordered = 0x100; // bencode dictionary was not sorted
11 +
12 enum type_type {
13 TYPE_NONE,
14 TYPE_VALUE,
15 @@ -109,6 +111,9 @@
16 void set_flags(uint32_t f) { m_flags |= f & mask_public; }
17 void unset_flags(uint32_t f) { m_flags &= ~(f & mask_public); }
18
19 + void set_internal_flags(uint32_t f) { m_flags |= f & (mask_internal & ~mask_type); }
20 + void unset_internal_flags(uint32_t f) { m_flags &= ~(f & (mask_internal & ~mask_type)); }
21 +
22 // Add functions for setting/clearing the public flags.
23
24 bool is_value() const { return type() == TYPE_VALUE; }
25 Index: libtorrent/src/torrent/object_stream.cc
26 ===================================================================
27 --- libtorrent/src/torrent/object_stream.cc (revision 1093)
28 +++ libtorrent/src/torrent/object_stream.cc (working copy)
29 @@ -96,6 +96,9 @@
30
31 Object::list_iterator itr = object->as_list().insert(object->as_list().end(), Object());
32 object_read_bencode(input, &*itr, depth);
33 +
34 + if (itr->flags() & Object::flag_unordered)
35 + object->set_internal_flags(Object::flag_unordered);
36 }
37
38 break;
39 @@ -107,7 +110,7 @@
40 if (++depth >= 1024)
41 break;
42
43 - // Object::string_type last;
44 + Object::string_type last;
45
46 while (input->good()) {
47 if (input->peek() == 'e') {
48 @@ -120,12 +123,16 @@
49 if (!object_read_string(input, str))
50 break;
51
52 - // if (last >= str)
53 - // break;
54 + if (last >= str)
55 + object->set_internal_flags(Object::flag_unordered);
56
57 - object_read_bencode(input, &object->as_map()[str], depth);
58 + Object* value = &object->as_map()[str];
59 + object_read_bencode(input, value, depth);
60
61 - // str.swap(last);
62 + if (value->flags() & Object::flag_unordered)
63 + object->set_internal_flags(Object::flag_unordered);
64 +
65 + str.swap(last);
66 }
67
68 break;
69 Index: libtorrent/src/download/download_constructor.cc
70 ===================================================================
71 --- libtorrent/src/download/download_constructor.cc (revision 1093)
72 +++ libtorrent/src/download/download_constructor.cc (working copy)
73 @@ -132,6 +132,9 @@
74 if (!fileList->empty())
75 throw internal_error("parse_info received an already initialized Content object.");
76
77 + if (b.flags() & Object::flag_unordered)
78 + throw input_error("Download has unordered info dictionary.");
79 +
80 uint32_t chunkSize = b.get_key_value("piece length");
81
82 if (chunkSize <= (1 << 10) || chunkSize > (128 << 20))