]> git.saurik.com Git - apt.git/commitdiff
implement VerifyFile as all-hashes check
authorDavid Kalnischkies <david@kalnischkies.de>
Tue, 12 May 2015 09:18:17 +0000 (11:18 +0200)
committerDavid Kalnischkies <david@kalnischkies.de>
Tue, 12 May 2015 11:29:54 +0000 (13:29 +0200)
It isn't used much compared to what the methodname suggests, but in the
remaining uses it can't hurt to check more than strictly necessary by
calculating and verifying with all hashes we can compare with rather
than "just" the best known hash.

apt-pkg/acquire-item.cc
apt-pkg/contrib/hashes.cc

index 01ce0e6503029c31ef9712d49edc4ee503e0a3b7..1090912f5cdb45e08a065b1c23e0959506e37db7 100644 (file)
@@ -1175,7 +1175,7 @@ void pkgAcqIndexMergeDiffs::Done(string Message,unsigned long long Size,HashStri
    else if (State == StateApplyDiff)
    {
       // see if we really got the expected file
-      if(ExpectedHashes.usable() && !ExpectedHashes.VerifyFile(DestFile))
+      if(ExpectedHashes.usable() && ExpectedHashes != Hashes)
       {
         RenameOnError(HashSumMismatch);
         return;
index 953465091e4f9a593ff9c2362a3e41707b7e03d0..0fa443b4abed2f43391e4e4a6e05246246b42e47 100644 (file)
@@ -204,15 +204,22 @@ bool HashStringList::push_back(const HashString &hashString)              /*{{{*/
                                                                        /*}}}*/
 bool HashStringList::VerifyFile(std::string filename) const            /*{{{*/
 {
-   if (list.empty() == true)
-      return false;
-   HashString const * const hs = find(NULL);
-   if (hs == NULL || hs->VerifyFile(filename) == false)
+   if (usable() == false)
       return false;
+
+   Hashes hashes(*this);
+   FileFd file(filename, FileFd::ReadOnly);
    HashString const * const hsf = find("Checksum-FileSize");
-   if (hsf != NULL && hsf->VerifyFile(filename) == false)
-      return false;
-   return true;
+   if (hsf != NULL)
+   {
+      std::string fileSize;
+      strprintf(fileSize, "%llu", file.FileSize());
+      if (hsf->HashValue() != fileSize)
+        return false;
+   }
+   hashes.AddFD(file);
+   HashStringList const hsl = hashes.GetHashStringList();
+   return hsl == *this;
 }
                                                                        /*}}}*/
 bool HashStringList::operator==(HashStringList const &other) const     /*{{{*/