diff options
author | Tao Bao <tbao@google.com> | 2019-10-03 23:12:55 -0700 |
---|---|---|
committer | Tao Bao <tbao@google.com> | 2019-10-03 23:21:22 -0700 |
commit | 22632cc82c0404bdbddaef41eb79cc99071894d0 (patch) | |
tree | 5904d85be45e73c3825f4029294b22b5ae0526d4 /tools/releasetools/validate_target_files.py | |
parent | 9c683dc968111364e887497435f2e689197b4888 (diff) | |
download | build_make-22632cc82c0404bdbddaef41eb79cc99071894d0.tar.gz build_make-22632cc82c0404bdbddaef41eb79cc99071894d0.tar.bz2 build_make-22632cc82c0404bdbddaef41eb79cc99071894d0.zip |
releasetools: Support verifying files with non-monotonic ranges.
Fixes: 79951650
Test: Run validate_target_files on target_files.zip with files in
non-monotonic ranges.
Test: python -m unittest test_validate_target_files
Test: python3 -m unittest test_validate_target_files
Change-Id: I82571d3358598775de4cdeb5e64035689fea6487
Diffstat (limited to 'tools/releasetools/validate_target_files.py')
-rwxr-xr-x | tools/releasetools/validate_target_files.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/tools/releasetools/validate_target_files.py b/tools/releasetools/validate_target_files.py index c299a488ae..d88ccc0a00 100755 --- a/tools/releasetools/validate_target_files.py +++ b/tools/releasetools/validate_target_files.py @@ -36,20 +36,21 @@ import logging import os.path import re import zipfile +from hashlib import sha1 import common +import rangelib def _ReadFile(file_name, unpacked_name, round_up=False): """Constructs and returns a File object. Rounds up its size if needed.""" - assert os.path.exists(unpacked_name) with open(unpacked_name, 'rb') as f: file_data = f.read() file_size = len(file_data) if round_up: file_size_rounded_up = common.RoundUpTo4K(file_size) - file_data += '\0' * (file_size_rounded_up - file_size) + file_data += b'\0' * (file_size_rounded_up - file_size) return common.File(file_name, file_data) @@ -96,13 +97,15 @@ def ValidateFileConsistency(input_zip, input_tmp, info_dict): logging.warning('Skipping %s that has incomplete block list', entry) continue - # TODO(b/79951650): Handle files with non-monotonic ranges. + # If the file has non-monotonic ranges, read each range in order. if not file_ranges.monotonic: - logging.warning( - 'Skipping %s that has non-monotonic ranges: %s', entry, file_ranges) - continue - - blocks_sha1 = image.RangeSha1(file_ranges) + h = sha1() + for file_range in file_ranges.extra['text_str'].split(' '): + for data in image.ReadRangeSet(rangelib.RangeSet(file_range)): + h.update(data) + blocks_sha1 = h.hexdigest() + else: + blocks_sha1 = image.RangeSha1(file_ranges) # The filename under unpacked directory, such as SYSTEM/bin/sh. unpacked_name = os.path.join( |