Check sum of file length does not exceed INT64_MAX

With BitTorrent or Metalink (metaurl), one RequestGroup can contain
multiple files. In this change, ensure that the sum of thoese files
must be equal or less than INT64_MAX.
pull/25/merge
Tatsuhiro Tsujikawa 2012-07-23 21:57:02 +09:00
parent 860f4dd06a
commit 4b57106a17
2 changed files with 8 additions and 0 deletions

View File

@ -57,6 +57,7 @@
#include "download_helper.h"
#include "fmt.h"
#include "SegList.h"
#include "DownloadFailureException.h"
#ifdef ENABLE_BITTORRENT
# include "BtDependency.h"
# include "download_helper.h"
@ -313,6 +314,10 @@ Metalink2RequestGroup::createRequestGroup
}
fe->setOriginalName((*i)->metaurls[0]->name);
fileEntries.push_back(fe);
if(offset >
std::numeric_limits<int64_t>::max() - (*i)->file->getLength()) {
throw DOWNLOAD_FAILURE_EXCEPTION(fmt(EX_TOO_LARGE_FILE, offset));
}
offset += (*i)->file->getLength();
}
dctx->setFileEntries(fileEntries.begin(), fileEntries.end());

View File

@ -248,6 +248,9 @@ void extractFileEntries
throw DL_ABORT_EX2(fmt(MSG_MISSING_BT_INFO, C_LENGTH.c_str()),
error_code::BITTORRENT_PARSE_ERROR);
}
if(length > std::numeric_limits<int64_t>::max() - fileLengthData->i()) {
throw DOWNLOAD_FAILURE_EXCEPTION(fmt(EX_TOO_LARGE_FILE, length));
}
length += fileLengthData->i();
if(fileLengthData->i() > std::numeric_limits<off_t>::max()) {
throw DOWNLOAD_FAILURE_EXCEPTION(fmt(EX_TOO_LARGE_FILE, length));