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 #include +#include #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((size_t)infoHashLength); - READ_CHECK(fp, savedInfoHash.get(), infoHashLength); + std::array 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