diff options
author | Tianjie Xu <xunchang@google.com> | 2017-04-28 20:31:23 +0200 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-04-28 20:31:23 +0200 |
commit | 36e3388bdcb89d7e996d2474b8d4241c791473f0 (patch) | |
tree | 070034cd066c6582236130e04def570dce817493 /update_verifier/update_verifier.cpp | |
parent | Adding support for quiescent reboot to recovery (diff) | |
parent | Merge "Fix potential OOM in update_verifier" am: 5443072c3c (diff) | |
download | android_bootable_recovery-36e3388bdcb89d7e996d2474b8d4241c791473f0.tar android_bootable_recovery-36e3388bdcb89d7e996d2474b8d4241c791473f0.tar.gz android_bootable_recovery-36e3388bdcb89d7e996d2474b8d4241c791473f0.tar.bz2 android_bootable_recovery-36e3388bdcb89d7e996d2474b8d4241c791473f0.tar.lz android_bootable_recovery-36e3388bdcb89d7e996d2474b8d4241c791473f0.tar.xz android_bootable_recovery-36e3388bdcb89d7e996d2474b8d4241c791473f0.tar.zst android_bootable_recovery-36e3388bdcb89d7e996d2474b8d4241c791473f0.zip |
Diffstat (limited to 'update_verifier/update_verifier.cpp')
-rw-r--r-- | update_verifier/update_verifier.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/update_verifier/update_verifier.cpp b/update_verifier/update_verifier.cpp index 1950cbd83..fdbcfde56 100644 --- a/update_verifier/update_verifier.cpp +++ b/update_verifier/update_verifier.cpp @@ -44,6 +44,7 @@ #include <string.h> #include <unistd.h> +#include <algorithm> #include <string> #include <vector> @@ -142,17 +143,21 @@ static bool read_blocks(const std::string& partition, const std::string& range_s return false; } - static constexpr int BLOCKSIZE = 4096; + static constexpr size_t BLOCKSIZE = 4096; if (lseek64(fd.get(), static_cast<off64_t>(range_start) * BLOCKSIZE, SEEK_SET) == -1) { PLOG(ERROR) << "lseek to " << range_start << " failed"; return false; } - size_t size = (range_end - range_start) * BLOCKSIZE; - std::vector<uint8_t> buf(size); - if (!android::base::ReadFully(fd.get(), buf.data(), size)) { - PLOG(ERROR) << "Failed to read blocks " << range_start << " to " << range_end; - return false; + size_t remain = (range_end - range_start) * BLOCKSIZE; + while (remain > 0) { + size_t to_read = std::min(remain, 1024 * BLOCKSIZE); + std::vector<uint8_t> buf(to_read); + if (!android::base::ReadFully(fd.get(), buf.data(), to_read)) { + PLOG(ERROR) << "Failed to read blocks " << range_start << " to " << range_end; + return false; + } + remain -= to_read; } blk_count += (range_end - range_start); } |