fixed utf-8 verification bug and filename collision resolver

This commit is contained in:
Arvid Norberg 2013-02-24 10:16:57 +00:00
parent 3599b130c0
commit 7b53dd0491
3 changed files with 17 additions and 9 deletions

View File

@ -14,6 +14,8 @@
* fix uTP edge case where udp socket buffer fills up * fix uTP edge case where udp socket buffer fills up
* fix nagle implementation in uTP * fix nagle implementation in uTP
* fix bug filename collision resolver
* fix bug in filename utf-8 verification
* make need_save_resume() a bit more robust * make need_save_resume() a bit more robust
* fixed sparse flag manipulation on windows * fixed sparse flag manipulation on windows
* fixed streaming piece picking issue * fixed streaming piece picking issue

View File

@ -160,7 +160,7 @@ namespace libtorrent
} }
// valid 4-byte utf-8 character // valid 4-byte utf-8 character
if ((i[0] & 0xf0) == 0xe0 if ((i[0] & 0xf8) == 0xf0
&& (i[1] & 0xc0) == 0x80 && (i[1] & 0xc0) == 0x80
&& (i[2] & 0xc0) == 0x80 && (i[2] & 0xc0) == 0x80
&& (i[3] & 0xc0) == 0x80) && (i[3] & 0xc0) == 0x80)
@ -354,6 +354,13 @@ namespace libtorrent
{ {
if (list.type() != lazy_entry::list_t) return false; if (list.type() != lazy_entry::list_t) return false;
target.reserve(list.list_size()); target.reserve(list.list_size());
// TODO: 1 this logic should be a separate step
// done once the torrent is loaded, and the original
// filenames should be preserved!
int cnt = 0;
std::set<std::string, string_less_no_case> files;
for (int i = 0, end(list.list_size()); i < end; ++i) for (int i = 0, end(list.list_size()); i < end; ++i)
{ {
lazy_entry const* file_hash = 0; lazy_entry const* file_hash = 0;
@ -364,20 +371,13 @@ namespace libtorrent
, &file_hash, &fee, &mtime)) , &file_hash, &fee, &mtime))
return false; return false;
// TODO: 1 this logic should be a separate step
// done once the torrent is loaded, and the original
// filenames should be preserved!
int cnt = 0;
std::set<std::string, string_less_no_case> files;
// as long as this file already exists // as long as this file already exists
// increase the counter // increase the counter
fprintf(stderr, "adding file: %s\n", e.path.c_str());
while (!files.insert(e.path).second) while (!files.insert(e.path).second)
{ {
++cnt; ++cnt;
char suffix[50]; char suffix[50];
snprintf(suffix, sizeof(suffix), ".%d%s", cnt, extension(e.path).c_str()); snprintf(suffix, sizeof(suffix), "%d%s", cnt, extension(e.path).c_str());
replace_extension(e.path, suffix); replace_extension(e.path, suffix);
} }
target.add_file(e, file_hash ? file_hash->string_ptr() + info_ptr_diff : 0); target.add_file(e, file_hash ? file_hash->string_ptr() + info_ptr_diff : 0);

View File

@ -1392,6 +1392,12 @@ int test_main()
comparison.resize(TORRENT_MAX_PATH); comparison.resize(TORRENT_MAX_PATH);
TEST_EQUAL(test, comparison); TEST_EQUAL(test, comparison);
// replace_extension
test = "foo.bar";
replace_extension(test, "txt");
TEST_EQUAL(test, "foo.txt");
// file class // file class
file f; file f;
#if TORRENT_USE_UNC_PATHS || !defined WIN32 #if TORRENT_USE_UNC_PATHS || !defined WIN32