diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-09-01 11:59:34 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-09-01 11:59:34 +0000 |
| commit | a5fe2a837ddb8695eebb6f2f4d856d6ff6a19656 (patch) | |
| tree | 3af3baf2a17bfc2fbb7d68417e85daae0392dc95 | |
| parent | cb083125821acfcfbb1e4a4d8ecbd81829df7981 (diff) | |
2008-09-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Made files whose name ends with ".gz", ".tgz" not inflated by
Content
Encoding Decoder. Removed size threshold for turning off on the
fly
inflation because resulting file may or may not be inflated
depending
on the file size and I think it is not expected by users.
This change fixes segmentation fault when Metalink file contains
gzipped
file and its filesize is provided.
* src/HttpResponseCommand.cc
* src/HttpResponseCommand.h
| -rw-r--r-- | ChangeLog | 11 | ||||
| -rw-r--r-- | src/HttpResponseCommand.cc | 58 | ||||
| -rw-r--r-- | src/HttpResponseCommand.h | 8 |
3 files changed, 49 insertions, 28 deletions
@@ -1,5 +1,16 @@ 2008-09-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> + Made files whose name ends with ".gz", ".tgz" not inflated by Content + Encoding Decoder. Removed size threshold for turning off on the fly + inflation because resulting file may or may not be inflated depending + on the file size and I think it is not expected by users. + This change fixes segmentation fault when Metalink file contains gzipped + file and its filesize is provided. + * src/HttpResponseCommand.cc + * src/HttpResponseCommand.h + +2008-09-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> + Fixed chunk checksum validation cannot detect trailing garbage data. BUG#2074141 * src/AbstractSingleDiskAdaptor.cc diff --git a/src/HttpResponseCommand.cc b/src/HttpResponseCommand.cc index 929d7992..4103b18e 100644 --- a/src/HttpResponseCommand.cc +++ b/src/HttpResponseCommand.cc @@ -61,7 +61,6 @@ #include "StringFormat.h" #include "HttpSkipResponseCommand.h" #include "HttpHeader.h" -#include "Decoder.h" #include "LogFactory.h" namespace aria2 { @@ -136,6 +135,13 @@ bool HttpResponseCommand::executeInternal() } } +static bool fileIsGzipped(const SharedHandle<HttpResponse>& httpResponse) +{ + std::string filename = + Util::toLower(httpResponse->getHttpRequest()->getRequest()->getFile()); + return Util::endsWith(filename, ".gz") || Util::endsWith(filename, ".tgz"); +} + bool HttpResponseCommand::shouldInflateContentEncoding (const SharedHandle<HttpResponse>& httpResponse) { @@ -143,14 +149,11 @@ bool HttpResponseCommand::shouldInflateContentEncoding // because in each segment we don't know where the date should be written. // So turn off segmented downloading. // Meanwhile, Some server returns content-encoding: gzip for .tgz files. - // Those files tend to be large enough to speed up using segmented - // downloading. Therefore, I choose threshold size to determine on the fly - // inflation should be done. I expect gzipped content such as metalink xml - // files tend to be smaller than the threshold size, those contents are - // inflated on the fly properly. + // I think those files should not be inflated by clients, because it is the + // original format of those files. So I made filename ending ".gz" or ".tgz" + // (case-insensitive) not inflated. return httpResponse->isContentEncodingSpecified() && - httpResponse->getEntityLength() <= - static_cast<uint64_t>(e->option->getAsInt(PREF_SEGMENT_SIZE)); + !fileIsGzipped(httpResponse); } bool HttpResponseCommand::handleDefaultEncoding(const HttpResponseHandle& httpResponse) @@ -194,19 +197,6 @@ bool HttpResponseCommand::handleDefaultEncoding(const HttpResponseHandle& httpRe return true; } -bool HttpResponseCommand::handleOtherEncoding(const HttpResponseHandle& httpResponse) { - HttpRequestHandle httpRequest = httpResponse->getHttpRequest(); - // quick hack for method 'head',, is it necessary? - if(httpRequest->getMethod() == Request::METHOD_HEAD) { - return true; - } - _requestGroup->initPieceStorage(); - _requestGroup->shouldCancelDownloadForSafety(); - _requestGroup->getPieceStorage()->getDiskAdaptor()->initAndOpenFile(); - e->commands.push_back(createHttpDownloadCommand(httpResponse)); - return true; -} - static SharedHandle<Decoder> getTransferEncodingDecoder (const SharedHandle<HttpResponse>& httpResponse) { @@ -242,6 +232,22 @@ static SharedHandle<Decoder> getContentEncodingDecoder return decoder; } +bool HttpResponseCommand::handleOtherEncoding(const HttpResponseHandle& httpResponse) { + HttpRequestHandle httpRequest = httpResponse->getHttpRequest(); + // quick hack for method 'head',, is it necessary? + if(httpRequest->getMethod() == Request::METHOD_HEAD) { + return true; + } + _requestGroup->initPieceStorage(); + _requestGroup->shouldCancelDownloadForSafety(); + _requestGroup->getPieceStorage()->getDiskAdaptor()->initAndOpenFile(); + e->commands.push_back + (createHttpDownloadCommand(httpResponse, + getTransferEncodingDecoder(httpResponse), + getContentEncodingDecoder(httpResponse))); + return true; +} + bool HttpResponseCommand::skipResponseBody (const SharedHandle<HttpResponse>& httpResponse) { @@ -266,12 +272,10 @@ bool HttpResponseCommand::skipResponseBody } HttpDownloadCommand* HttpResponseCommand::createHttpDownloadCommand -(const HttpResponseHandle& httpResponse) +(const HttpResponseHandle& httpResponse, + const SharedHandle<Decoder>& transferEncodingDecoder, + const SharedHandle<Decoder>& contentEncodingDecoder) { - SharedHandle<Decoder> transferEncodingDecoder = - getTransferEncodingDecoder(httpResponse); - SharedHandle<Decoder> contentEncodingDecoder = - getContentEncodingDecoder(httpResponse); HttpDownloadCommand* command = new HttpDownloadCommand(cuid, req, _requestGroup, httpConnection, e, @@ -283,7 +287,7 @@ HttpDownloadCommand* HttpResponseCommand::createHttpDownloadCommand (e->option->getAsInt(PREF_LOWEST_SPEED_LIMIT)); command->setTransferEncodingDecoder(transferEncodingDecoder); - if(shouldInflateContentEncoding(httpResponse)) { + if(!contentEncodingDecoder.isNull()) { command->setContentEncodingDecoder(contentEncodingDecoder); // Since the compressed file's length are returned in the response header // and the decompressed file size is unknown at this point, disable file diff --git a/src/HttpResponseCommand.h b/src/HttpResponseCommand.h index 6cb410be..6162b2ca 100644 --- a/src/HttpResponseCommand.h +++ b/src/HttpResponseCommand.h @@ -36,6 +36,7 @@ #define _D_HTTP_RESPONSE_COMMAND_H_ #include "AbstractCommand.h" +#include "Decoder.h" namespace aria2 { @@ -52,7 +53,12 @@ private: bool handleOtherEncoding(const SharedHandle<HttpResponse>& httpResponse); bool skipResponseBody(const SharedHandle<HttpResponse>& httpResponse); - HttpDownloadCommand* createHttpDownloadCommand(const SharedHandle<HttpResponse>& httpResponse); + HttpDownloadCommand* + createHttpDownloadCommand(const SharedHandle<HttpResponse>& httpResponse, + const SharedHandle<Decoder>& transferEncodingDecoder + = SharedHandle<Decoder>(), + const SharedHandle<Decoder>& contentEncodingDecoder + = SharedHandle<Decoder>()); protected: bool executeInternal(); |
