mirror of https://github.com/aria2/aria2
Workaround for crash on EX_INVALID_RANGE_HEADER
Seems to save the download in some casespull/1869/head
parent
c546fa492c
commit
74370a7646
|
@ -53,6 +53,7 @@
|
||||||
#include "Request.h"
|
#include "Request.h"
|
||||||
#include "DownloadHandlerConstants.h"
|
#include "DownloadHandlerConstants.h"
|
||||||
#include "MessageDigest.h"
|
#include "MessageDigest.h"
|
||||||
|
#include "LogFactory.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -124,7 +125,7 @@ bool HttpRequest::isRangeSatisfied(const Range& range) const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return getStartByte() == range.startByte &&
|
return getStartByte() == range.startByte &&
|
||||||
(getEndByte() == 0 || getEndByte() == range.endByte) &&
|
(getEndByte() == 0 || getEndByte() <= range.endByte) &&
|
||||||
(fileEntry_->getLength() == 0 ||
|
(fileEntry_->getLength() == 0 ||
|
||||||
fileEntry_->getLength() == range.entityLength);
|
fileEntry_->getLength() == range.entityLength);
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,12 +78,26 @@ void HttpResponse::validateResponse() const
|
||||||
// compare the received range against the requested range
|
// compare the received range against the requested range
|
||||||
auto responseRange = httpHeader_->getRange();
|
auto responseRange = httpHeader_->getRange();
|
||||||
if (!httpRequest_->isRangeSatisfied(responseRange)) {
|
if (!httpRequest_->isRangeSatisfied(responseRange)) {
|
||||||
throw DL_ABORT_EX2(
|
if ( httpRequest_->getEndByte() > 0 &&
|
||||||
fmt(EX_INVALID_RANGE_HEADER, httpRequest_->getStartByte(),
|
httpRequest_->getEndByte() <= responseRange.endByte){
|
||||||
httpRequest_->getEndByte(), httpRequest_->getEntityLength(),
|
// Some servers return full length of file as endByte
|
||||||
responseRange.startByte, responseRange.endByte,
|
// regardless of what was requested.
|
||||||
responseRange.entityLength),
|
// If server offers more, ignore for a while and hope for the best.
|
||||||
error_code::CANNOT_RESUME);
|
|
||||||
|
A2_LOG_WARN( fmt(MSG_STRANGE_RANGE_HEADER, cuid_,
|
||||||
|
httpRequest_->getStartByte(),
|
||||||
|
httpRequest_->getEndByte(), httpRequest_->getEntityLength(),
|
||||||
|
responseRange.startByte, responseRange.endByte,
|
||||||
|
responseRange.entityLength));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw DL_ABORT_EX2(
|
||||||
|
fmt(EX_INVALID_RANGE_HEADER, httpRequest_->getStartByte(),
|
||||||
|
httpRequest_->getEndByte(), httpRequest_->getEntityLength(),
|
||||||
|
responseRange.startByte, responseRange.endByte,
|
||||||
|
responseRange.entityLength),
|
||||||
|
error_code::CANNOT_RESUME);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -211,6 +211,7 @@
|
||||||
#define MSG_REMOVING_UNSELECTED_FILE _("GID#%s - Removing unselected file.")
|
#define MSG_REMOVING_UNSELECTED_FILE _("GID#%s - Removing unselected file.")
|
||||||
#define MSG_FILE_REMOVED _("File %s removed.")
|
#define MSG_FILE_REMOVED _("File %s removed.")
|
||||||
#define MSG_FILE_COULD_NOT_REMOVED _("File %s could not be removed.")
|
#define MSG_FILE_COULD_NOT_REMOVED _("File %s could not be removed.")
|
||||||
|
#define MSG_STRANGE_RANGE_HEADER "CUID#%" PRId64 " Strange range header. Request: %" PRId64 "-%" PRId64 "/%" PRId64 ", Response: %" PRId64 "-%" PRId64 "/%" PRId64 ""
|
||||||
|
|
||||||
#define EX_TIME_OUT _("Timeout.")
|
#define EX_TIME_OUT _("Timeout.")
|
||||||
#define EX_INVALID_CHUNK_SIZE _("Invalid chunk size.")
|
#define EX_INVALID_CHUNK_SIZE _("Invalid chunk size.")
|
||||||
|
|
Loading…
Reference in New Issue