forked from premiere/premiere-libtorrent
extended utf-8 encoding error correction to also cover name, comment and created by. Fixes #372
This commit is contained in:
parent
e01f628b8e
commit
aecc24171d
|
@ -34,6 +34,8 @@ release 0.14.2
|
|||
renamed file names instead of the original file names in the torrent.
|
||||
* documentation fix of queing section
|
||||
* fixed potential issue in udp_socket (affected udp tracker support)
|
||||
* made name, comment and created by also be subject to utf-8 error
|
||||
correction (filenames already were)
|
||||
|
||||
release 0.14.1
|
||||
|
||||
|
|
|
@ -107,6 +107,7 @@ int main(int argc, char* argv[])
|
|||
std::cout << "comment: " << t.comment() << "\n";
|
||||
std::cout << "created by: " << t.creator() << "\n";
|
||||
std::cout << "magnet link: " << make_magnet_uri(t) << "\n";
|
||||
std::cout << "name: " << t.name() << "\n";
|
||||
std::cout << "files:\n";
|
||||
int index = 0;
|
||||
for (torrent_info::file_iterator i = t.begin_files();
|
||||
|
|
|
@ -75,13 +75,12 @@ namespace
|
|||
str += 0x80 | (chr & 0x3f);
|
||||
}
|
||||
|
||||
void verify_encoding(file_entry& target)
|
||||
bool verify_encoding(std::string& target)
|
||||
{
|
||||
std::string tmp_path;
|
||||
std::string file_path = target.path.string();
|
||||
bool valid_encoding = true;
|
||||
for (std::string::iterator i = file_path.begin()
|
||||
, end(file_path.end()); i != end; ++i)
|
||||
for (std::string::iterator i = target.begin()
|
||||
, end(target.end()); i != end; ++i)
|
||||
{
|
||||
// valid ascii-character
|
||||
if ((*i & 0x80) == 0)
|
||||
|
@ -154,7 +153,14 @@ namespace
|
|||
// save the original encoding and replace the
|
||||
// commonly used path with the correctly
|
||||
// encoded string
|
||||
if (!valid_encoding) target.path = tmp_path;
|
||||
if (!valid_encoding) target = tmp_path;
|
||||
return valid_encoding;
|
||||
}
|
||||
|
||||
void verify_encoding(file_entry& target)
|
||||
{
|
||||
std::string p = target.path.string();
|
||||
if (!verify_encoding(p)) target.path = p;
|
||||
}
|
||||
|
||||
void trim_path_element(std::string& path_element)
|
||||
|
@ -489,6 +495,9 @@ namespace libtorrent
|
|||
error = "invalid 'name' of torrent (possible exploit attempt)";
|
||||
return false;
|
||||
}
|
||||
|
||||
// correct utf-8 encoding errors
|
||||
verify_encoding(name);
|
||||
|
||||
// extract file list
|
||||
lazy_entry const* i = info.dict_find_list("files");
|
||||
|
@ -669,9 +678,11 @@ namespace libtorrent
|
|||
|
||||
m_comment = torrent_file.dict_find_string_value("comment.utf-8");
|
||||
if (m_comment.empty()) m_comment = torrent_file.dict_find_string_value("comment");
|
||||
verify_encoding(m_comment);
|
||||
|
||||
m_created_by = torrent_file.dict_find_string_value("created by.utf-8");
|
||||
if (m_created_by.empty()) m_created_by = torrent_file.dict_find_string_value("created by");
|
||||
verify_encoding(m_created_by);
|
||||
|
||||
lazy_entry const* info = torrent_file.dict_find_dict("info");
|
||||
if (info == 0)
|
||||
|
|
Loading…
Reference in New Issue