From 089941c800e57ffadbeef24a38410b415448713d Mon Sep 17 00:00:00 2001 From: liyong Date: Fri, 28 Jun 2019 15:05:12 +0800 Subject: [PATCH] Fix unsigned type sub overflow issue when isntall DSU writer->size() is block size aligned and could be bigger than remaining_bytes If remaining_bytes is bigger, set remaining_bytes to 0 to avoid sub overflow error. Bug: 136727859 Test: Successfully install a DSU Change-Id: If493b0f206561239caec2ee234f7cfd70bf927a7 --- fs_mgr/libfiemap_writer/split_fiemap_writer.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs_mgr/libfiemap_writer/split_fiemap_writer.cpp b/fs_mgr/libfiemap_writer/split_fiemap_writer.cpp index a0ccc10f7..16a82d287 100644 --- a/fs_mgr/libfiemap_writer/split_fiemap_writer.cpp +++ b/fs_mgr/libfiemap_writer/split_fiemap_writer.cpp @@ -95,8 +95,9 @@ std::unique_ptr SplitFiemap::Create(const std::string& file_path, u // To make sure the alignment doesn't create too much inconsistency, we // account the *actual* size, not the requested size. total_bytes_written += writer->size(); - remaining_bytes -= writer->size(); - + // writer->size() is block size aligned and could be bigger than remaining_bytes + // If remaining_bytes is bigger, set remaining_bytes to 0 to avoid underflow error. + remaining_bytes = remaining_bytes > writer->size() ? (remaining_bytes - writer->size()) : 0; out->AddFile(std::move(writer)); }