Browse Source

Always use the same limits when parse bencoded data

PR #19263.
adaptive-webui-19844
Vladimir Golovnev 2 years ago committed by GitHub
parent
commit
80c637bf99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      src/base/bittorrent/bencoderesumedatastorage.cpp
  2. 6
      src/base/bittorrent/common.h
  3. 7
      src/base/bittorrent/dbresumedatastorage.cpp
  4. 8
      src/base/bittorrent/torrentinfo.cpp
  5. 2
      src/base/global.h
  6. 1
      src/gui/addnewtorrentdialog.cpp

7
src/base/bittorrent/bencoderesumedatastorage.cpp

@ -49,6 +49,7 @@ @@ -49,6 +49,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"
@ -201,7 +202,8 @@ void BitTorrent::BencodeResumeDataStorage::loadQueue(const Path &queueFilename) @@ -201,7 +202,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())));
@ -268,7 +270,8 @@ BitTorrent::LoadResumeDataResult BitTorrent::BencodeResumeDataStorage::loadTorre @@ -268,7 +270,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())));

6
src/base/bittorrent/common.h

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2020 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2020-2023 Vladimir Golovnev <glassez@yandex.ru>
*
* 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 @@ @@ -33,3 +33,7 @@
#include "base/global.h"
inline const QString QB_EXT = u".!qB"_s;
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;

7
src/base/bittorrent/dbresumedatastorage.cpp

@ -58,6 +58,7 @@ @@ -58,6 +58,7 @@
#include "base/profile.h"
#include "base/utils/fs.h"
#include "base/utils/string.h"
#include "common.h"
#include "infohash.h"
#include "loadtorrentparams.h"
@ -247,7 +248,8 @@ namespace @@ -247,7 +248,8 @@ namespace
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;
@ -256,7 +258,8 @@ namespace @@ -256,7 +258,8 @@ namespace
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<lt::torrent_info>(torentInfoRoot, ec);
}

8
src/base/bittorrent/torrentinfo.cpp

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2015-2023 Vladimir Golovnev <glassez@yandex.ru>
*
* 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 @@ @@ -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"
@ -85,12 +86,9 @@ nonstd::expected<TorrentInfo, QString> TorrentInfo::load(const QByteArray &data) @@ -85,12 +86,9 @@ nonstd::expected<TorrentInfo, QString> 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()));

2
src/base/global.h

@ -35,8 +35,6 @@ @@ -35,8 +35,6 @@
#define QBT_APP_64BIT
#endif
inline const int MAX_TORRENT_SIZE = 100 * 1024 * 1024; // 100 MiB
template <typename T>
constexpr typename std::add_const_t<T> &asConst(T &t) noexcept { return t; }

1
src/gui/addnewtorrentdialog.cpp

@ -43,6 +43,7 @@ @@ -43,6 +43,7 @@
#include <QUrl>
#include <QVector>
#include "base/bittorrent/common.h"
#include "base/bittorrent/downloadpriority.h"
#include "base/bittorrent/infohash.h"
#include "base/bittorrent/magneturi.h"

Loading…
Cancel
Save