summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYi-Yo Chiang <yochiang@google.com>2021-02-12 01:57:44 +0800
committerYo Chiang <yochiang@google.com>2021-02-17 09:03:30 +0000
commit23a996fde114247e6f2f67df37d955a640e9775b (patch)
tree6c4b0a188949657ddaed694ea4262d72deaeec63
parent645cdedb2fe69c57fc10df7efe933cbdcadfb8aa (diff)
downloadgsid-23a996fde114247e6f2f67df37d955a640e9775b.tar.gz
Explicitly cast to 64bit integer when calculating filesystem size
Else the result may overflow on platforms that have 32bit long. Bug: 179980369 Test: Install DSU on 32bit cuttlefish and observe logcat. Test: Try installing with different userdata size and verify the calculated filesystem size. Change-Id: I50b140590972e733e0e45047b2ce8a6735d205f7
-rw-r--r--partition_installer.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/partition_installer.cpp b/partition_installer.cpp
index fea1483..79af71a 100644
--- a/partition_installer.cpp
+++ b/partition_installer.cpp
@@ -126,8 +126,8 @@ int PartitionInstaller::PerformSanityChecks() {
// This is the same as android::vold::GetFreebytes() but we also
// need the total file system size so we open code it here.
- uint64_t free_space = 1ULL * sb.f_bavail * sb.f_frsize;
- uint64_t fs_size = sb.f_blocks * sb.f_frsize;
+ uint64_t free_space = static_cast<uint64_t>(sb.f_bavail) * sb.f_frsize;
+ uint64_t fs_size = static_cast<uint64_t>(sb.f_blocks) * sb.f_frsize;
if (free_space <= (size_)) {
LOG(ERROR) << "not enough free space (only " << free_space << " bytes available)";
return IGsiService::INSTALL_ERROR_NO_SPACE;