From a0732906aedf3c35e3ea21c0902ca237b81d15cc Mon Sep 17 00:00:00 2001 From: Cheng Chang Date: Mon, 27 Dec 2021 16:40:29 +0800 Subject: Fix non-ab fuse ota fail bug Fix the 'Calculate the offset to last partial block' logic in ReadBlockAligndData. If file_size % fuse_block_size_ < source_block_size_, the origin map logic will get a wrong block address of last block. This bug leads to the non-ab fuse ota fail. Test: compare the md5 of origin pkg and pkg reading from fuse. Change-Id: Ic5132a7e9919cc2e91390231be342b97421ea23e --- fuse_sideload/fuse_provider.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fuse_sideload/fuse_provider.cpp b/fuse_sideload/fuse_provider.cpp index 8fa1b5c2e..2183d0844 100644 --- a/fuse_sideload/fuse_provider.cpp +++ b/fuse_sideload/fuse_provider.cpp @@ -118,11 +118,16 @@ bool FuseBlockDataProvider::ReadBlockAlignedData(uint8_t* buffer, uint32_t fetch } if (uint64_t tailing_bytes = fetch_size % source_block_size_; tailing_bytes != 0) { - // Calculate the offset to last partial block. + // Calculate the offset to last partial block. Two possibilities as below: + // 1: fetch_size < source_block_size_, the read_ranges is a blank range_set. + // Get the last block num through GetBlockNumber() of the offset block. + // 2: fetch_size >= source_block_size_, the last block num is already stored + // in read-ranges by GetSubRanges() above. uint64_t tailing_offset = read_ranges.value() ? static_cast((read_ranges->cend() - 1)->second) * source_block_size_ - : static_cast(start_block) * source_block_size_; + : static_cast(ranges_.GetBlockNumber(offset / source_block_size_)) * + source_block_size_; if (!android::base::ReadFullyAtOffset(fd_, next_out, tailing_bytes, tailing_offset)) { PLOG(ERROR) << "Failed to read tailing " << tailing_bytes << " bytes at offset " << tailing_offset; -- cgit v1.2.3