From 312d6ea822750f74be7d26488f9b054d2c83e04e Mon Sep 17 00:00:00 2001 From: matejcik Date: Thu, 25 Jun 2020 11:23:26 +0200 Subject: [PATCH] python: fix padding in first chunk (fixes #1082) --- python/CHANGELOG.md | 8 ++++++++ python/src/trezorlib/firmware.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/python/CHANGELOG.md b/python/CHANGELOG.md index f4a3d41b2..751661a44 100644 --- a/python/CHANGELOG.md +++ b/python/CHANGELOG.md @@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). _At the moment, the project does **not** adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). That is expected to change with version 1.0._ +## [0.12.1] - unreleased +[0.12.1]: https://github.com/trezor/trezor-firmware/compare/python/v0.12.0...master + +### Fixed + +- correctly calculate hashes for very small firmwares [f#1082] + ## [0.12.0] - 2020-04-01 [0.12.0]: https://github.com/trezor/trezor-firmware/compare/python/v0.11.6...python/v0.12.0 @@ -422,3 +429,4 @@ _At the moment, the project does **not** adhere to [Semantic Versioning](https:/ [f#681]: https://github.com/trezor/trezor-firmware/issues/681 [f#778]: https://github.com/trezor/trezor-firmware/issues/778 [f#823]: https://github.com/trezor/trezor-firmware/issues/823 +[f#1082]: https://github.com/trezor/trezor-firmware/issues/1082 diff --git a/python/src/trezorlib/firmware.py b/python/src/trezorlib/firmware.py index 21e67eab7..74831d414 100644 --- a/python/src/trezorlib/firmware.py +++ b/python/src/trezorlib/firmware.py @@ -363,7 +363,7 @@ def calculate_code_hashes( chunk = code[start:end] # padding for last non-empty chunk if padding_byte is not None and start < len(code) and end > len(code): - chunk += padding_byte[0:1] * (chunk_size - len(chunk)) + chunk += padding_byte[0:1] * (end - start - len(chunk)) if not chunk: hashes.append(b"\0" * 32)