Version: 3.3.92 (using KDE Devel) Installed from: Compiled sources Compiler: GCC 3.4.1 MandrakeLinux 10.1, i686 OS: Linux Reproducable: always Steps to reproduce: 1. download the attached torrent file 2. right click on file and select properties to see meta info Actual result: The torrent length is not correct. Konqueror shows that it is 70.6 MB. BitTorent and Azureus both show that the length is 4368951330 bytes or 4.07 GiB. Expected result: Konqueror should show that the length is 4.07 GiB.
Created attachment 9502 [details] Sample torrent file Use this torrent file to see the incorrectly shown length info.
Looks like a 32-bit overflow somewhere in the code.
CVS commit by mpyne: Fix bug 98942 (Reported file length incorrect), caused by 32-bit integer overflow. Will backport. BUG:98942 M +6 -5 kfile_torrent.cpp 1.5 --- kdenetwork/kfile-plugins/torrent/kfile_torrent.cpp #1.4:1.5 @@ -36,5 +36,5 @@ K_EXPORT_COMPONENT_FACTORY(kfile_torrent QStringList filesList (BList *list); -unsigned int filesLength (BList *list); +Q_ULLONG filesLength (BList *list); KTorrentPlugin::KTorrentPlugin (QObject *parent, const char *name, @@ -69,5 +69,5 @@ KTorrentPlugin::KTorrentPlugin (QObject setAttributes (item, KFileMimeTypeInfo::Modifiable); - item = addItemInfo(group, "length", i18n("Torrent Length"), QVariant::Int); + item = addItemInfo(group, "length", i18n("Torrent Length"), QVariant::ULongLong); if (!item) { @@ -193,5 +193,6 @@ bool KTorrentPlugin::readInfo (KFileMeta // it. BDict *info_dict = m_dict->findDict("info"); - int num_files = 1, length = 0; + int num_files = 1; + Q_ULLONG length = 0; if (!info_dict) @@ -315,7 +316,7 @@ QStringList filesList (BList *list) * The list provided should be the same one provided for filesList. */ -unsigned int filesLength (BList *list) +Q_ULLONG filesLength (BList *list) { - int length = 0; + Q_ULLONG length = 0; for (unsigned int i = 0; i < list->count(); ++i)
CVS commit by mpyne: Backport fix for bug 98942 (reported file length incorrect) to KDE 3.4 CCBUG:98942 M +1 -1 bint.cpp 1.1.2.1 M +1 -1 bint.h 1.1.2.1 M +1 -1 blist.cpp 1.2.2.1 M +1 -1 bytetape.cpp 1.3.2.1 M +6 -5 kfile_torrent.cpp 1.4.2.1 --- kdenetwork/kfile-plugins/torrent/bint.h #1.1:1.1.2.1 @@ -103,5 +103,5 @@ class BInt : public BBase void init(ByteTape &tape); - int m_value; + Q_LLONG m_value; bool m_valid; }; --- kdenetwork/kfile-plugins/torrent/bint.cpp #1.1:1.1.2.1 @@ -63,5 +63,5 @@ void BInt::init (ByteTape &tape) bool a_isValid; // We want to make sure the string is a valid number - m_value = numberString.toInt(&a_isValid); + m_value = numberString.toLongLong(&a_isValid); tape += length; // Move to 'e' --- kdenetwork/kfile-plugins/torrent/blist.cpp #1.2:1.2.2.1 @@ -89,5 +89,5 @@ BList::~BList() BBase* BList::index (unsigned int i) { - if ((i < 0) || (i >= count())) + if (i >= count()) return 0; else --- kdenetwork/kfile-plugins/torrent/bytetape.cpp #1.3:1.3.2.1 @@ -24,5 +24,5 @@ ByteTape::ByteTape (QByteArray &array, i : m_array(array), m_shared(new ByteTapeShared) { - m_shared->pos = 0; + m_shared->pos = pos; } --- kdenetwork/kfile-plugins/torrent/kfile_torrent.cpp #1.4:1.4.2.1 @@ -36,5 +36,5 @@ K_EXPORT_COMPONENT_FACTORY(kfile_torrent QStringList filesList (BList *list); -unsigned int filesLength (BList *list); +Q_ULLONG filesLength (BList *list); KTorrentPlugin::KTorrentPlugin (QObject *parent, const char *name, @@ -69,5 +69,5 @@ KTorrentPlugin::KTorrentPlugin (QObject setAttributes (item, KFileMimeTypeInfo::Modifiable); - item = addItemInfo(group, "length", i18n("Torrent Length"), QVariant::Int); + item = addItemInfo(group, "length", i18n("Torrent Length"), QVariant::ULongLong); if (!item) { @@ -193,5 +193,6 @@ bool KTorrentPlugin::readInfo (KFileMeta // it. BDict *info_dict = m_dict->findDict("info"); - int num_files = 1, length = 0; + int num_files = 1; + Q_ULLONG length = 0; if (!info_dict) @@ -315,7 +316,7 @@ QStringList filesList (BList *list) * The list provided should be the same one provided for filesList. */ -unsigned int filesLength (BList *list) +Q_ULLONG filesLength (BList *list) { - int length = 0; + Q_ULLONG length = 0; for (unsigned int i = 0; i < list->count(); ++i)