From 702a779edb5d71d9f1be82713482a51ff69a8a3d Mon Sep 17 00:00:00 2001 From: Ray Chin Date: Tue, 23 May 2023 17:43:50 +0800 Subject: [PATCH] Fix overflow issue when computing ideal size of scratch partition The type of f_frsize is `unsigned long` which is 32 bit for some system so it will overflow after multiplied by f_bfree. This solution adds one more type casting to ensure the type is 64 bit unsigned integer during the computing. Bug: 281599020 Test: adb root; adb shell disable-verity Change-Id: I377ed722d5e245c235c3ae12ff66ac7e91d1d6e8 --- fs_mgr/fs_mgr_overlayfs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs_mgr/fs_mgr_overlayfs.cpp b/fs_mgr/fs_mgr_overlayfs.cpp index ef436e580..f04fc8d2f 100644 --- a/fs_mgr/fs_mgr_overlayfs.cpp +++ b/fs_mgr/fs_mgr_overlayfs.cpp @@ -1083,7 +1083,7 @@ static inline uint64_t GetIdealDataScratchSize() { return 0; } - auto ideal_size = std::min(super_info.size, uint64_t(s.f_frsize * s.f_bfree * 0.85)); + auto ideal_size = std::min(super_info.size, uint64_t(uint64_t(s.f_frsize) * s.f_bfree * 0.85)); // Align up to the filesystem block size. if (auto remainder = ideal_size % s.f_bsize; remainder > 0) {