mirror of
https://github.com/aria2/aria2.git
synced 2025-04-03 04:27:38 +03:00
Merge pull request #2127 from aria2/cap-infohashlen
Cap infoHashLength in .aria2 file
This commit is contained in:
commit
d066c72a0d
1 changed files with 7 additions and 6 deletions
|
@ -36,6 +36,7 @@
|
|||
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <array>
|
||||
|
||||
#include "PieceStorage.h"
|
||||
#include "Piece.h"
|
||||
|
@ -263,21 +264,21 @@ void DefaultBtProgressInfoFile::load()
|
|||
if (version >= 1) {
|
||||
infoHashLength = ntohl(infoHashLength);
|
||||
}
|
||||
if (infoHashLength == 0 && infoHashCheckEnabled) {
|
||||
if (infoHashLength > INFO_HASH_LENGTH ||
|
||||
(infoHashLength != INFO_HASH_LENGTH && infoHashCheckEnabled)) {
|
||||
throw DL_ABORT_EX(fmt("Invalid info hash length: %d", infoHashLength));
|
||||
}
|
||||
if (infoHashLength > 0) {
|
||||
auto savedInfoHash = make_unique<unsigned char[]>((size_t)infoHashLength);
|
||||
READ_CHECK(fp, savedInfoHash.get(), infoHashLength);
|
||||
std::array<unsigned char, INFO_HASH_LENGTH> savedInfoHash;
|
||||
READ_CHECK(fp, savedInfoHash.data(), infoHashLength);
|
||||
#ifdef ENABLE_BITTORRENT
|
||||
if (infoHashCheckEnabled) {
|
||||
const unsigned char* infoHash = bittorrent::getInfoHash(dctx_);
|
||||
if (infoHashLength != INFO_HASH_LENGTH ||
|
||||
memcmp(savedInfoHash.get(), infoHash, INFO_HASH_LENGTH) != 0) {
|
||||
if (memcmp(savedInfoHash.data(), infoHash, INFO_HASH_LENGTH) != 0) {
|
||||
throw DL_ABORT_EX(
|
||||
fmt("info hash mismatch. expected: %s, actual: %s",
|
||||
util::toHex(infoHash, INFO_HASH_LENGTH).c_str(),
|
||||
util::toHex(savedInfoHash.get(), infoHashLength).c_str()));
|
||||
util::toHex(savedInfoHash.data(), infoHashLength).c_str()));
|
||||
}
|
||||
}
|
||||
#endif // ENABLE_BITTORRENT
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue