]> git.saurik.com Git - apt.git/commitdiff
Avoid overflow when summing up file sizes
authorJulian Andres Klode <jak@debian.org>
Mon, 7 Dec 2015 13:42:25 +0000 (14:42 +0100)
committerJulian Andres Klode <jak@debian.org>
Mon, 7 Dec 2015 13:44:15 +0000 (14:44 +0100)
We need to pass 0llu instead of 0 as the init value, otherwise
std::accumulate will calculate with ints.

Reported-by: Raphaƫl Hertzog
apt-pkg/acquire.cc
apt-pkg/deb/dpkgpm.cc

index b229a61b62297739accc7c8786b5a2af7576905b..cb8741603754ccdfa5b29c3d1492f17d2e388079 100644 (file)
@@ -730,7 +730,7 @@ bool pkgAcquire::Clean(string Dir)
 /* This is the total number of bytes needed */
 APT_PURE unsigned long long pkgAcquire::TotalNeeded()
 {
-   return std::accumulate(ItemsBegin(), ItemsEnd(), 0,
+   return std::accumulate(ItemsBegin(), ItemsEnd(), 0ull,
       [](unsigned long long const T, Item const * const I) {
         return T + I->FileSize;
    });
@@ -741,7 +741,7 @@ APT_PURE unsigned long long pkgAcquire::TotalNeeded()
 /* This is the number of bytes that is not local */
 APT_PURE unsigned long long pkgAcquire::FetchNeeded()
 {
-   return std::accumulate(ItemsBegin(), ItemsEnd(), 0,
+   return std::accumulate(ItemsBegin(), ItemsEnd(), 0llu,
       [](unsigned long long const T, Item const * const I) {
         if (I->Local == false)
            return T + I->FileSize;
@@ -755,7 +755,7 @@ APT_PURE unsigned long long pkgAcquire::FetchNeeded()
 /* This is the number of bytes that is not local */
 APT_PURE unsigned long long pkgAcquire::PartialPresent()
 {
-   return std::accumulate(ItemsBegin(), ItemsEnd(), 0,
+   return std::accumulate(ItemsBegin(), ItemsEnd(), 0llu,
       [](unsigned long long const T, Item const * const I) {
         if (I->Local == false)
            return T + I->PartialSize;
index 7355af9d507246205f202ff65bc3195b860ee1b0..ce92247914ef26e123cefda19f37bceb9814c36a 100644 (file)
@@ -1194,7 +1194,7 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress)
    std::vector<const char *> Args(sArgs.size(), NULL);
    std::transform(sArgs.begin(), sArgs.end(), Args.begin(),
         [](std::string const &s) { return s.c_str(); });
-   unsigned long long const StartSize = std::accumulate(sArgs.begin(), sArgs.end(), 0,
+   unsigned long long const StartSize = std::accumulate(sArgs.begin(), sArgs.end(), 0llu,
         [](unsigned long long const i, std::string const &s) { return i + s.length(); });
    size_t const BaseArgs = Args.size();