From 5a96dc613bce4bc01b8f1a1a285401c11cb3a2f9 Mon Sep 17 00:00:00 2001 From: mikecarper Date: Thu, 3 Sep 2026 01:08:28 -0700 Subject: [PATCH] Avoid overflow in OTA self block count --- src/helpers/ota/OtaSelf.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/ota/OtaSelf.cpp b/src/helpers/ota/OtaSelf.cpp index 5efed2799..446d372b2 100644 --- a/src/helpers/ota/OtaSelf.cpp +++ b/src/helpers/ota/OtaSelf.cpp @@ -148,7 +148,7 @@ bool ota_serve_self(OtaContext& c, uint32_t fw_version) { // independent transport-DEFLATE stream more useful history than the deployed 1 KiB geometry. A ~530 KiB // image is about 265 blocks (roughly 1 KiB of leaves) instead of ~4,240 128-byte leaves. const uint32_t image_size = fi.image_len, BS = OTA_DEFAULT_BLOCK_SIZE; - const uint32_t bc = (image_size + BS - 1) / BS; + const uint32_t bc = image_size / BS + (image_size % BS != 0 ? 1u : 0u); if ((uint64_t)bc * 4 > OTA_SELF_LEAVES_MAX) return false; free(c.serve_self_leaves); free(c.serve_self_proof);