HTTPRepository: don’t crash on empty files
Fix some additional crash cases around 0-length files
This commit is contained in:
@@ -438,32 +438,37 @@ public:
|
|||||||
|
|
||||||
ArchiveExtractTask(const ArchiveExtractTask &) = delete;
|
ArchiveExtractTask(const ArchiveExtractTask &) = delete;
|
||||||
|
|
||||||
HTTPRepoPrivate::ProcessResult run(HTTPRepoPrivate *repo) {
|
HTTPRepoPrivate::ProcessResult run(HTTPRepoPrivate* repo)
|
||||||
size_t rd = file.read((char *)buffer, bufferSize);
|
{
|
||||||
extractor.extractBytes(buffer, rd);
|
if (!buffer) {
|
||||||
|
return HTTPRepoPrivate::ProcessFailed;
|
||||||
if (file.eof()) {
|
|
||||||
extractor.flush();
|
|
||||||
file.close();
|
|
||||||
|
|
||||||
if (!extractor.isAtEndOfArchive()) {
|
|
||||||
SG_LOG(SG_TERRASYNC, SG_ALERT, "Corrupt tarball " << relativePath);
|
|
||||||
repo->failedToUpdateChild(relativePath,
|
|
||||||
HTTPRepository::REPO_ERROR_IO);
|
|
||||||
return HTTPRepoPrivate::ProcessFailed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extractor.hasError()) {
|
size_t rd = file.read((char*)buffer, bufferSize);
|
||||||
SG_LOG(SG_TERRASYNC, SG_ALERT, "Error extracting " << relativePath);
|
extractor.extractBytes(buffer, rd);
|
||||||
repo->failedToUpdateChild(relativePath,
|
|
||||||
HTTPRepository::REPO_ERROR_IO);
|
if (file.eof()) {
|
||||||
return HTTPRepoPrivate::ProcessFailed;
|
extractor.flush();
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
if (!extractor.isAtEndOfArchive()) {
|
||||||
|
SG_LOG(SG_TERRASYNC, SG_ALERT, "Corrupt tarball " << relativePath);
|
||||||
|
repo->failedToUpdateChild(relativePath,
|
||||||
|
HTTPRepository::REPO_ERROR_IO);
|
||||||
|
return HTTPRepoPrivate::ProcessFailed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (extractor.hasError()) {
|
||||||
|
SG_LOG(SG_TERRASYNC, SG_ALERT, "Error extracting " << relativePath);
|
||||||
|
repo->failedToUpdateChild(relativePath,
|
||||||
|
HTTPRepository::REPO_ERROR_IO);
|
||||||
|
return HTTPRepoPrivate::ProcessFailed;
|
||||||
|
}
|
||||||
|
|
||||||
|
return HTTPRepoPrivate::ProcessDone;
|
||||||
}
|
}
|
||||||
|
|
||||||
return HTTPRepoPrivate::ProcessDone;
|
return HTTPRepoPrivate::ProcessContinue;
|
||||||
}
|
|
||||||
|
|
||||||
return HTTPRepoPrivate::ProcessContinue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~ArchiveExtractTask() { free(buffer); }
|
~ArchiveExtractTask() { free(buffer); }
|
||||||
@@ -974,6 +979,8 @@ HTTPRepository::failure() const
|
|||||||
{
|
{
|
||||||
pathInRepo = _directory->absolutePath();
|
pathInRepo = _directory->absolutePath();
|
||||||
pathInRepo.append(fileName);
|
pathInRepo.append(fileName);
|
||||||
|
|
||||||
|
sha1_init(&hashContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -986,8 +993,6 @@ HTTPRepository::failure() const
|
|||||||
_directory->repository()->http->cancelRequest(
|
_directory->repository()->http->cancelRequest(
|
||||||
this, "Unable to create output file:" + pathInRepo.utf8Str());
|
this, "Unable to create output file:" + pathInRepo.utf8Str());
|
||||||
}
|
}
|
||||||
|
|
||||||
sha1_init(&hashContext);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sha1_write(&hashContext, s, n);
|
sha1_write(&hashContext, s, n);
|
||||||
|
|||||||
Reference in New Issue
Block a user