summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2023-11-02 21:22:37 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2023-11-02 21:22:37 +0900
commit3330110cafebd86b231d860cddea2f36ca8e755c (patch)
treeee7491829e330fe92a749f1bc45818f1001e5a17 /src
parentd607327ea6dd969c5ccdfa3e4d2693efcddac0b5 (diff)
Cap infoHashLength in .aria2 file
Cap infoHashLength in .aria2 file, and save an extra allocation.
Diffstat (limited to 'src')
-rw-r--r--src/DefaultBtProgressInfoFile.cc13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/DefaultBtProgressInfoFile.cc b/src/DefaultBtProgressInfoFile.cc
index b2161828..9d03e3e9 100644
--- a/src/DefaultBtProgressInfoFile.cc
+++ b/src/DefaultBtProgressInfoFile.cc
@@ -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