Commit 387242e4 authored by Jarryd's avatar Jarryd Committed by Commit Bot

Quota: Avoid integer overflow.

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/+/2429365Reviewed-by: default avatarMarijn Kruisselbrink <mek@chromium.org>
Commit-Queue: Jarryd Goodman <jarrydg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810769}
parent 1f5e8fea
...@@ -53,7 +53,7 @@ constexpr int64_t kReportHistogramInterval = 60 * 60 * 1000; // 1 hour ...@@ -53,7 +53,7 @@ constexpr int64_t kReportHistogramInterval = 60 * 60 * 1000; // 1 hour
// Take action on write errors if there is <= 2% disk space // Take action on write errors if there is <= 2% disk space
// available. // available.
constexpr double kStoragePressureThresholdPercent = 2; constexpr double kStoragePressureThresholdRatio = 0.02;
// Limit how frequently QuotaManager polls for free disk space when // Limit how frequently QuotaManager polls for free disk space when
// only using that information to identify storage pressure. // only using that information to identify storage pressure.
...@@ -1487,7 +1487,7 @@ void QuotaManager::MaybeRunStoragePressureCallback(const url::Origin& origin, ...@@ -1487,7 +1487,7 @@ void QuotaManager::MaybeRunStoragePressureCallback(const url::Origin& origin,
return; return;
} }
if (100 * available_space < kStoragePressureThresholdPercent * total_space) { if (available_space < kStoragePressureThresholdRatio * total_space) {
storage_pressure_callback_.Run(std::move(origin)); storage_pressure_callback_.Run(std::move(origin));
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment