Commit db5d5779 authored by erikchen's avatar erikchen Committed by Commit Bot

Fix underflow in computation of PrivateMemoryFootprint on macOS.

The underflow was occurring during subtraction of two uints, before the
saturated_cast could fix the result.

Bug: 812346
Change-Id: I08acf91e137880fe7aba0d41f8ea362c9f81315c
Reviewed-on: https://chromium-review.googlesource.com/955908Reviewed-by: default avatarPrimiano Tucci <primiano@chromium.org>
Commit-Queue: Erik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543533}
parent 4c9b3be4
......@@ -46,15 +46,18 @@ uint32_t CalculatePrivateFootprintKb(const mojom::RawOSMemDump& os_dump,
if (base::mac::IsAtLeastOS10_12()) {
uint64_t phys_footprint_bytes =
os_dump.platform_private_footprint->phys_footprint_bytes;
return base::saturated_cast<uint32_t>(phys_footprint_bytes / 1024 -
shared_resident_kb);
return base::saturated_cast<uint32_t>(
base::saturated_cast<int32_t>(phys_footprint_bytes / 1024) -
base::saturated_cast<int32_t>(shared_resident_kb));
} else {
uint64_t internal_bytes =
os_dump.platform_private_footprint->internal_bytes;
uint64_t compressed_bytes =
os_dump.platform_private_footprint->compressed_bytes;
return base::saturated_cast<uint32_t>(
(internal_bytes + compressed_bytes) / 1024 - shared_resident_kb);
base::saturated_cast<int32_t>((internal_bytes + compressed_bytes) /
1024) -
base::saturated_cast<int32_t>(shared_resident_kb));
}
#elif defined(OS_WIN)
return os_dump.platform_private_footprint->private_bytes / 1024;
......
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