diff --git a/Telegram/SourceFiles/core/file_location.cpp b/Telegram/SourceFiles/core/file_location.cpp index f9c927f7f..8d2eef458 100644 --- a/Telegram/SourceFiles/core/file_location.cpp +++ b/Telegram/SourceFiles/core/file_location.cpp @@ -16,6 +16,7 @@ namespace Core { namespace { const auto kInMediaCacheLocation = u"*media_cache*"_q; +constexpr auto kMaxFileSize = 4000 * int64(1024 * 1024); } // namespace @@ -55,13 +56,13 @@ FileLocation::FileLocation(const QFileInfo &info) : fname(info.filePath()) { void FileLocation::resolveFromInfo(const QFileInfo &info) { if (info.exists()) { const auto s = info.size(); - if (s > INT_MAX) { + if (s > kMaxFileSize) { fname = QString(); _bookmark = nullptr; size = 0; } else { modified = info.lastModified(); - size = qint32(s); + size = s; } } else { fname = QString(); @@ -88,12 +89,12 @@ bool FileLocation::check() const { if (!f.isReadable()) return false; quint64 s = f.size(); - if (s > INT_MAX) { + if (s > kMaxFileSize) { DEBUG_LOG(("File location check: Wrong size %1").arg(s)); return false; } - if (qint32(s) != size) { + if (s != size) { DEBUG_LOG(("File location check: Wrong size %1 when should be %2").arg(s).arg(size)); return false; } diff --git a/Telegram/SourceFiles/core/file_location.h b/Telegram/SourceFiles/core/file_location.h index f1c62930b..a7d89a5d3 100644 --- a/Telegram/SourceFiles/core/file_location.h +++ b/Telegram/SourceFiles/core/file_location.h @@ -55,7 +55,7 @@ public: QString fname; QDateTime modified; - qint32 size; + qint64 size = 0; private: void resolveFromInfo(const QFileInfo &info); diff --git a/Telegram/SourceFiles/data/data_download_manager.cpp b/Telegram/SourceFiles/data/data_download_manager.cpp index f344c4f2f..c1cdf47ba 100644 --- a/Telegram/SourceFiles/data/data_download_manager.cpp +++ b/Telegram/SourceFiles/data/data_download_manager.cpp @@ -39,7 +39,7 @@ namespace Data { namespace { constexpr auto kClearLoadingTimeout = 5 * crl::time(1000); -constexpr auto kMaxFileSize = 2000 * 1024 * 1024; +constexpr auto kMaxFileSize = 4000 * int64(1024 * 1024); constexpr auto kMaxResolvePerAttempt = 100; constexpr auto ByItem = [](const auto &entry) { @@ -944,7 +944,7 @@ Fn()> DownloadManager::serializator( const auto constant = sizeof(quint64) // download.objectId + sizeof(qint32) // download.type + sizeof(qint64) // started - + sizeof(qint32) // size + + sizeof(quint32) // size + sizeof(quint64) // itemId.peer + sizeof(qint64) // itemId.msg + sizeof(quint64); // peerAccessHash @@ -963,7 +963,8 @@ Fn()> DownloadManager::serializator( << quint64(id.download.objectId) << qint32(id.download.type) << qint64(id.started) - << qint32(id.size) + // FileSize: Right now any file size fits 32 bit. + << quint32(id.size) << quint64(id.itemId.peer.value) << qint64(id.itemId.msg.bare) << quint64(id.peerAccessHash) @@ -996,7 +997,8 @@ std::vector DownloadManager::deserialize( auto downloadObjectId = quint64(); auto uncheckedDownloadType = qint32(); auto started = qint64(); - auto size = qint32(); + // FileSize: Right now any file size fits 32 bit. + auto size = quint32(); auto itemIdPeer = quint64(); auto itemIdMsg = qint64(); auto peerAccessHash = quint64(); @@ -1026,7 +1028,7 @@ std::vector DownloadManager::deserialize( }, .started = started, .path = path, - .size = size, + .size = int64(size), .itemId = { PeerId(itemIdPeer), MsgId(itemIdMsg) }, .peerAccessHash = peerAccessHash, }); diff --git a/Telegram/SourceFiles/storage/storage_account.cpp b/Telegram/SourceFiles/storage/storage_account.cpp index a10ffd5e0..2cfb1f657 100644 --- a/Telegram/SourceFiles/storage/storage_account.cpp +++ b/Telegram/SourceFiles/storage/storage_account.cpp @@ -730,12 +730,14 @@ void Account::readLocations() { QByteArray bookmark; Core::FileLocation loc; quint32 legacyTypeField = 0; + quint32 size = 0; locations.stream >> first >> second >> legacyTypeField >> loc.fname; if (locations.version > 9013) { locations.stream >> bookmark; } - locations.stream >> loc.modified >> loc.size; + locations.stream >> loc.modified >> size; loc.setBookmark(bookmark); + loc.size = int64(size); if (!first && !second && !legacyTypeField && loc.fname.isEmpty() && !loc.size) { // end mark endMarkFound = true;