Skip to content

Commit

Permalink
Quota: Avoid integer overflow.
Browse files Browse the repository at this point in the history
In the storage pressure check, we multiply available space by 100.
The max value of an int64_t is 2^63, so an overflow could happen on
a disk whose size is at least 2^63 / 100 ~= 92 PB. This change
refactors the storage pressure check by representing the storage
pressure threshold (2%) as 0.02 rather than 2, which allows us to
remove the multiplication by 100 on the other side of the equation.

Bug: 1127237
Change-Id: If3d5a89ee2cd8ea8f0beabf1a38ae71a14d3ff52
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2429365
Reviewed-by: Marijn Kruisselbrink <mek@chromium.org>
Commit-Queue: Jarryd Goodman <jarrydg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810769}
  • Loading branch information
Jarryd authored and Commit Bot committed Sep 25, 2020
1 parent 1f5e8fe commit 387242e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions storage/browser/quota/quota_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ constexpr int64_t kReportHistogramInterval = 60 * 60 * 1000; // 1 hour

// Take action on write errors if there is <= 2% disk space
// available.
constexpr double kStoragePressureThresholdPercent = 2;
constexpr double kStoragePressureThresholdRatio = 0.02;

// Limit how frequently QuotaManager polls for free disk space when
// only using that information to identify storage pressure.
Expand Down Expand Up @@ -1487,7 +1487,7 @@ void QuotaManager::MaybeRunStoragePressureCallback(const url::Origin& origin,
return;
}

if (100 * available_space < kStoragePressureThresholdPercent * total_space) {
if (available_space < kStoragePressureThresholdRatio * total_space) {
storage_pressure_callback_.Run(std::move(origin));
}
}
Expand Down

0 comments on commit 387242e

Please sign in to comment.