summaryrefslogtreecommitdiff
path: root/src/HttpHeader.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2011-12-09 01:12:54 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2011-12-09 21:39:43 +0900
commit31163c6785364cea045ed07fefa541f6f414c1d1 (patch)
treee31882137ea35e7ddd1bc3696f6e16178d4b1104 /src/HttpHeader.cc
parent7989cd898dc0bfef40ab1a7e2b747676620d6517 (diff)
Check totalLength of file is less than std::numeric_limits<off_t>::max()
If totalLength is larger than std::numeric_limits<off_t>::max(), throw DownloadFailureException.
Diffstat (limited to 'src/HttpHeader.cc')
-rw-r--r--src/HttpHeader.cc27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc
index ff6aa8d9..8513cb56 100644
--- a/src/HttpHeader.cc
+++ b/src/HttpHeader.cc
@@ -36,6 +36,7 @@
#include "Range.h"
#include "util.h"
#include "A2STR.h"
+#include "DownloadFailureException.h"
namespace aria2 {
@@ -136,11 +137,13 @@ RangeHandle HttpHeader::getRange() const
if(clenStr.empty()) {
return SharedHandle<Range>(new Range());
} else {
- off_t contentLength = util::parseLLInt(clenStr);
+ int64_t contentLength = util::parseLLInt(clenStr);
if(contentLength < 0) {
throw DL_ABORT_EX("Content-Length must be positive");
- }
- if(contentLength == 0) {
+ } else if(contentLength > std::numeric_limits<off_t>::max()) {
+ throw DOWNLOAD_FAILURE_EXCEPTION
+ (fmt(EX_TOO_LARGE_FILE, static_cast<long long int>(contentLength)));
+ } else if(contentLength == 0) {
return SharedHandle<Range>(new Range());
} else {
return SharedHandle<Range>
@@ -176,13 +179,25 @@ RangeHandle HttpHeader::getRange() const
if(minus == slash) {
return SharedHandle<Range>(new Range());
}
- off_t startByte = util::parseLLInt(std::string(byteRangeSpec, minus));
- off_t endByte = util::parseLLInt(std::string(minus+1, slash));
- off_t entityLength =
+ int64_t startByte = util::parseLLInt(std::string(byteRangeSpec, minus));
+ int64_t endByte = util::parseLLInt(std::string(minus+1, slash));
+ int64_t entityLength =
util::parseLLInt(std::string(slash+1, rangeStr.end()));
if(startByte < 0 || endByte < 0 || entityLength < 0) {
throw DL_ABORT_EX("byte-range-spec must be positive");
}
+ if(startByte > std::numeric_limits<off_t>::max()) {
+ throw DOWNLOAD_FAILURE_EXCEPTION
+ (fmt(EX_TOO_LARGE_FILE, static_cast<long long int>(startByte)));
+ }
+ if(endByte > std::numeric_limits<off_t>::max()) {
+ throw DOWNLOAD_FAILURE_EXCEPTION
+ (fmt(EX_TOO_LARGE_FILE, static_cast<long long int>(endByte)));
+ }
+ if(entityLength > std::numeric_limits<off_t>::max()) {
+ throw DOWNLOAD_FAILURE_EXCEPTION
+ (fmt(EX_TOO_LARGE_FILE, static_cast<long long int>(entityLength)));
+ }
return SharedHandle<Range>(new Range(startByte, endByte, entityLength));
}