Przeglądaj źródła

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.
Tatsuhiro Tsujikawa 13 lat temu
rodzic
commit
4b57106a17
2 zmienionych plików z 8 dodań i 0 usunięć
  1. 5 0
      src/Metalink2RequestGroup.cc
  2. 3 0
      src/bittorrent_helper.cc

+ 5 - 0
src/Metalink2RequestGroup.cc

@@ -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());

+ 3 - 0
src/bittorrent_helper.cc

@@ -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));