summaryrefslogtreecommitdiff
path: root/apt-pkg/acquire-item.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2016-03-14 01:09:32 +0100
committerDavid Kalnischkies <david@kalnischkies.de>2016-03-14 11:47:19 +0100
commit4a808deaac462e7714a345dac676c6da294a2ee0 (patch)
tree56e3034fb37b1339ed0dc946de08448470f707e0 /apt-pkg/acquire-item.cc
parent8d0d92558c00d1825e413ce67be51a46a5c18aea (diff)
require $(HASH)-Download field in .diff/Index files
Now that we ignore SHA1-only files it makes sense to require also the provision of hashes for the compressed patches as this was introduced in the same patchset as support for non-SHA1 hashes in the file itself in dak and adding support in other archive creators (if they support pdiffs at all) will likely be in the same batch. The reason for the change itself is simple: If you are 'scared' enough about the security of SHA1, you shouldn't uncompress a file you haven't verified at all – after all, it could be exploiting a bug or a zip bomb.
Diffstat (limited to 'apt-pkg/acquire-item.cc')
-rw-r--r--apt-pkg/acquire-item.cc41
1 files changed, 17 insertions, 24 deletions
diff --git a/apt-pkg/acquire-item.cc b/apt-pkg/acquire-item.cc
index 2cf6b60a8..45f8cb76c 100644
--- a/apt-pkg/acquire-item.cc
+++ b/apt-pkg/acquire-item.cc
@@ -206,12 +206,12 @@ HashStringList pkgAcqMetaBase::GetExpectedHashes() const
APT_CONST bool pkgAcqIndexDiffs::HashesRequired() const
{
- /* We don't always have the diff of the downloaded pdiff file.
- What we have for sure is hashes for the uncompressed file,
- but rred uncompresses them on the fly while parsing, so not handled here.
- Hashes are (also) checked while searching for (next) patch to apply. */
+ /* We can't check hashes of rred result as we don't know what the
+ hash of the file will be. We just know the hash of the patch(es),
+ the hash of the file they will apply on and the hash of the resulting
+ file. */
if (State == StateFetchDiff)
- return available_patches[0].download_hashes.empty() == false;
+ return true;
return false;
}
HashStringList pkgAcqIndexDiffs::GetExpectedHashes() const
@@ -227,7 +227,7 @@ APT_CONST bool pkgAcqIndexMergeDiffs::HashesRequired() const
we can check the rred result after all patches are applied as
we know the expected result rather than potentially apply more patches */
if (State == StateFetchDiff)
- return patch.download_hashes.empty() == false;
+ return true;
return State == StateApplyDiff;
}
HashStringList pkgAcqIndexMergeDiffs::GetExpectedHashes() const
@@ -2022,6 +2022,17 @@ bool pkgAcqDiffIndex::ParseDiffIndex(string const &IndexDiffFile) /*{{{*/
return false;
}
+ for (auto const &patch: available_patches)
+ if (patch.result_hashes.usable() == false ||
+ patch.patch_hashes.usable() == false ||
+ patch.download_hashes.usable() == false)
+ {
+ if (Debug)
+ std::clog << "pkgAcqDiffIndex: " << IndexDiffFile << ": provides no usable hashes for " << patch.file
+ << " so fallback to complete download" << std::endl;
+ return false;
+ }
+
// patching with too many files is rather slow compared to a fast download
unsigned long const fileLimit = _config->FindI("Acquire::PDiffs::FileLimit", 0);
if (fileLimit != 0 && fileLimit < available_patches.size())
@@ -2036,7 +2047,6 @@ bool pkgAcqDiffIndex::ParseDiffIndex(string const &IndexDiffFile) /*{{{*/
unsigned short const sizeLimitPercent = _config->FindI("Acquire::PDiffs::SizeLimit", 100);
if (sizeLimitPercent > 0 && TransactionManager->MetaIndexParser != nullptr)
{
- // compressed case
unsigned long long downloadSize = std::accumulate(available_patches.begin(),
available_patches.end(), 0llu, [](unsigned long long const T, DiffInfo const &I) {
return T + I.download_hashes.FileSize();
@@ -2065,23 +2075,6 @@ bool pkgAcqDiffIndex::ParseDiffIndex(string const &IndexDiffFile) /*{{{*/
return false;
}
}
- // uncompressed case
- downloadSize = std::accumulate(available_patches.begin(),
- available_patches.end(), 0llu, [](unsigned long long const T, DiffInfo const &I) {
- return T + I.patch_hashes.FileSize();
- });
- if (downloadSize != 0)
- {
- unsigned long long const downloadSizeIdx = ServerSize;
- unsigned long long const sizeLimit = downloadSizeIdx * sizeLimitPercent;
- if ((sizeLimit/100) < downloadSize)
- {
- if (Debug)
- std::clog << "Need " << downloadSize << " uncompressed bytes (Limit is " << (sizeLimit/100) << ", "
- << "original is " << downloadSizeIdx << ") so fallback to complete download" << std::endl;
- return false;
- }
- }
}
// we have something, queue the diffs