From e86d1bccc0ab1c60903939308870e7de8cf94231 Mon Sep 17 00:00:00 2001 From: Tianjie Xu Date: Wed, 26 Feb 2020 21:50:47 -0800 Subject: [PATCH] Preserve the monotonic property when subtracting 0 block The monotonic property of the range is lost after the recent change to subtract 0th block from the file range. As a result, we read the block in the wrong order when pull files from the raw image. This yields a incorrect hash during validation. Bug: 150334561 Test: run validate_target_file. unittests Change-Id: Id4fedaaf273c42c8d21a4549fda4c9a45e22066a (cherry picked from commit f02ececc7f76bf77f988e4a02c50771a808e9673) --- tools/releasetools/sparse_img.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/releasetools/sparse_img.py b/tools/releasetools/sparse_img.py index 6a91cf454..524c0f297 100644 --- a/tools/releasetools/sparse_img.py +++ b/tools/releasetools/sparse_img.py @@ -250,13 +250,17 @@ class SparseImage(object): with open(fn) as f: for line in f: fn, ranges_text = line.rstrip().split(None, 1) - ranges = rangelib.RangeSet.parse(ranges_text) + raw_ranges = rangelib.RangeSet.parse(ranges_text) # Note: e2fsdroid records holes in the extent tree as "0" blocks. # This causes confusion because clobbered_blocks always includes # the superblock (physical block #0). Since the 0 blocks here do # not represent actual physical blocks, remove them from the set. - ranges = ranges.subtract(rangelib.RangeSet("0")) + ranges = raw_ranges.subtract(rangelib.RangeSet("0")) + # b/150334561 we need to perserve the monotonic property of the raw + # range. Otherwise, the validation script will read the blocks with + # wrong order when pulling files from the image. + ranges.monotonic = raw_ranges.monotonic ranges.extra['text_str'] = ranges_text if allow_shared_blocks: