From dd08c52eb83a522c43d2f9be1293aeec36871534 Mon Sep 17 00:00:00 2001 From: Daeho Jeong Date: Fri, 24 Mar 2023 14:51:53 -0700 Subject: [PATCH] vold: fix write kbytes handling Since Android platform codespace doesn't support exception handling, we use strtoll() instead of stoll for direct error handling. Bug: 274369737 Test: check smart idle maintenace service log Change-Id: I57c709b1e329228790e0a883edb64dc023135a24 --- IdleMaint.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/IdleMaint.cpp b/IdleMaint.cpp index 0c6b115..fedfc3d 100644 --- a/IdleMaint.cpp +++ b/IdleMaint.cpp @@ -630,7 +630,12 @@ static int32_t getLifeTimeWrite() { return -1; } - long long writeBytes = std::stoll(writeKbytesStr); + unsigned long long writeBytes = std::strtoull(writeKbytesStr.c_str(), NULL, 0); + /* Careful: values > LLONG_MAX can appear in the file due to a kernel bug. */ + if (writeBytes / KBYTES_IN_SEGMENT > INT32_MAX) { + LOG(WARNING) << "Bad lifetime_write_kbytes: " << writeKbytesStr; + return -1; + } return writeBytes / KBYTES_IN_SEGMENT; }