diff --git a/src/base/bittorrent/bencoderesumedatastorage.cpp b/src/base/bittorrent/bencoderesumedatastorage.cpp index b6f02ce22..764f24719 100644 --- a/src/base/bittorrent/bencoderesumedatastorage.cpp +++ b/src/base/bittorrent/bencoderesumedatastorage.cpp @@ -48,6 +48,7 @@ #include "base/utils/fs.h" #include "base/utils/io.h" #include "base/utils/string.h" +#include "common.h" #include "infohash.h" #include "loadtorrentparams.h" @@ -196,7 +197,8 @@ void BitTorrent::BencodeResumeDataStorage::loadQueue(const Path &queueFilename) BitTorrent::LoadResumeDataResult BitTorrent::BencodeResumeDataStorage::loadTorrentResumeData(const QByteArray &data, const QByteArray &metadata) const { lt::error_code ec; - const lt::bdecode_node resumeDataRoot = lt::bdecode(data, ec); + const lt::bdecode_node resumeDataRoot = lt::bdecode(data, ec + , nullptr, BENCODE_DEPTH_LIMIT, BENCODE_TOKEN_LIMIT); if (ec) return nonstd::make_unexpected(tr("Cannot parse resume data: %1").arg(QString::fromStdString(ec.message()))); @@ -263,7 +265,8 @@ BitTorrent::LoadResumeDataResult BitTorrent::BencodeResumeDataStorage::loadTorre if (!metadata.isEmpty()) { - const lt::bdecode_node torentInfoRoot = lt::bdecode(metadata, ec); + const lt::bdecode_node torentInfoRoot = lt::bdecode(metadata, ec + , nullptr, BENCODE_DEPTH_LIMIT, BENCODE_TOKEN_LIMIT); if (ec) return nonstd::make_unexpected(tr("Cannot parse torrent info: %1").arg(QString::fromStdString(ec.message()))); diff --git a/src/base/bittorrent/common.h b/src/base/bittorrent/common.h index b9dd66474..a7526ab9f 100644 --- a/src/base/bittorrent/common.h +++ b/src/base/bittorrent/common.h @@ -1,6 +1,6 @@ /* * Bittorrent Client using Qt and libtorrent. - * Copyright (C) 2020 Vladimir Golovnev + * Copyright (C) 2020-2023 Vladimir Golovnev * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -33,3 +33,7 @@ #include "base/global.h" inline const QString QB_EXT = u".!qB"_qs; + +inline const int MAX_TORRENT_SIZE = 100 * 1024 * 1024; // 100 MiB +inline const int BENCODE_DEPTH_LIMIT = 100; +inline const int BENCODE_TOKEN_LIMIT = 10'000'000; diff --git a/src/base/bittorrent/dbresumedatastorage.cpp b/src/base/bittorrent/dbresumedatastorage.cpp index 5dec4d7a6..c75d19218 100644 --- a/src/base/bittorrent/dbresumedatastorage.cpp +++ b/src/base/bittorrent/dbresumedatastorage.cpp @@ -1,6 +1,6 @@ /* * Bittorrent Client using Qt and libtorrent. - * Copyright (C) 2021-2022 Vladimir Golovnev + * Copyright (C) 2021-2023 Vladimir Golovnev * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -54,6 +54,7 @@ #include "base/profile.h" #include "base/utils/fs.h" #include "base/utils/string.h" +#include "common.h" #include "infohash.h" #include "loadtorrentparams.h" @@ -228,7 +229,8 @@ namespace BitTorrent const QByteArray bencodedResumeData = query.value(DB_COLUMN_RESUMEDATA.name).toByteArray(); lt::error_code ec; - const lt::bdecode_node resumeDataRoot = lt::bdecode(bencodedResumeData, ec); + const lt::bdecode_node resumeDataRoot = lt::bdecode(bencodedResumeData, ec + , nullptr, BENCODE_DEPTH_LIMIT, BENCODE_TOKEN_LIMIT); lt::add_torrent_params &p = resumeData.ltAddTorrentParams; @@ -236,7 +238,8 @@ namespace BitTorrent if (const QByteArray bencodedMetadata = query.value(DB_COLUMN_METADATA.name).toByteArray(); !bencodedMetadata.isEmpty()) { - const lt::bdecode_node torentInfoRoot = lt::bdecode(bencodedMetadata, ec); + const lt::bdecode_node torentInfoRoot = lt::bdecode(bencodedMetadata, ec + , nullptr, BENCODE_DEPTH_LIMIT, BENCODE_TOKEN_LIMIT); p.ti = std::make_shared(torentInfoRoot, ec); } diff --git a/src/base/bittorrent/torrentinfo.cpp b/src/base/bittorrent/torrentinfo.cpp index e2b7533df..8490bb7af 100644 --- a/src/base/bittorrent/torrentinfo.cpp +++ b/src/base/bittorrent/torrentinfo.cpp @@ -1,6 +1,6 @@ /* * Bittorrent Client using Qt and libtorrent. - * Copyright (C) 2015 Vladimir Golovnev + * Copyright (C) 2015-2023 Vladimir Golovnev * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -45,6 +45,7 @@ #include "base/utils/fs.h" #include "base/utils/io.h" #include "base/utils/misc.h" +#include "common.h" #include "infohash.h" #include "trackerentry.h" @@ -91,12 +92,9 @@ nonstd::expected TorrentInfo::load(const QByteArray &data) { // 2-step construction to overcome default limits of `depth_limit` & `token_limit` which are // used in `torrent_info()` constructor - const int depthLimit = 100; - const int tokenLimit = 10000000; - lt::error_code ec; const lt::bdecode_node node = lt::bdecode(data, ec - , nullptr, depthLimit, tokenLimit); + , nullptr, BENCODE_DEPTH_LIMIT, BENCODE_TOKEN_LIMIT); if (ec) return nonstd::make_unexpected(QString::fromStdString(ec.message())); diff --git a/src/base/global.h b/src/base/global.h index fdb251b94..ee6828f63 100644 --- a/src/base/global.h +++ b/src/base/global.h @@ -35,8 +35,6 @@ #define QBT_APP_64BIT #endif -inline const int MAX_TORRENT_SIZE = 100 * 1024 * 1024; // 100 MiB - template constexpr typename std::add_const_t &asConst(T &t) noexcept { return t; } diff --git a/src/gui/addnewtorrentdialog.cpp b/src/gui/addnewtorrentdialog.cpp index c6049fded..ed492790b 100644 --- a/src/gui/addnewtorrentdialog.cpp +++ b/src/gui/addnewtorrentdialog.cpp @@ -41,6 +41,7 @@ #include #include +#include "base/bittorrent/common.h" #include "base/bittorrent/downloadpriority.h" #include "base/bittorrent/infohash.h" #include "base/bittorrent/magneturi.h"