From f49ae656c3bd6e6d7a9598b5ecfa56b12049ad5c Mon Sep 17 00:00:00 2001 From: Hugo Grostabussiat Date: Fri, 7 Jun 2019 23:57:59 +0200 Subject: [PATCH] Immediately fail image verify if sizes don't match When verifying image integrity, first check the image file size against the one from the manifest. If they are different, fail immediately, without computing the SHA-256 hash of the image since we know it will be wrong. Unfortunately, there is no speed gain to expect from this optimization in the common case, since the uncompressed size of the image rarely change between builds. However, in cases where there are remains of a partially downloaded image, a new download will be attempted almost immediately. --- scripts/librem5-devkit-flash-image | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/librem5-devkit-flash-image b/scripts/librem5-devkit-flash-image index 9d2f26b..79bba36 100755 --- a/scripts/librem5-devkit-flash-image +++ b/scripts/librem5-devkit-flash-image @@ -68,6 +68,12 @@ def verify_image(image, meta): size = int(meta['image']['size']) hexdigest = meta['image']['sha256sum'] + filesize = os.path.getsize(image) + if filesize != size: + raise VerifyImageException( + "Image file \"{}\" size {} does not match {}".format( + os.path.basename(image), filesize, size)) + logging.info("Calculating sha256sum of {}".format(image)) bar = tqdm.tqdm(total=size, desc='Checking', -- GitLab