From 52ce6668d6d55a6d1ef9e54c87d9700c1ea306f9 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 28 Aug 2026 00:51:02 -0500 Subject: [PATCH] Reject ELFs with no allocated PROGBITS sections --- esphome/espidf/size_summary.py | 8 +++++++- tests/unit_tests/test_size_summary.py | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/esphome/espidf/size_summary.py b/esphome/espidf/size_summary.py index d8303d37dd..b6d0782974 100644 --- a/esphome/espidf/size_summary.py +++ b/esphome/espidf/size_summary.py @@ -74,7 +74,7 @@ def _find_app_partition_size(partitions_csv: Path) -> int: def _image_size_from_elf(elf: Path) -> int: - """Sum the loadable PROGBITS section sizes from an ELF32 file. + """Sum the allocated PROGBITS section sizes from an ELF32 file. Matches ``esp_idf_size.ng.memorymap._get_image_size`` byte for byte; esptool's ``ELFFile`` filters sections differently and would not. @@ -98,6 +98,9 @@ def _image_size_from_elf(elf: Path) -> int: (sh_size,) = struct.unpack_from(" flash_used = data.get("total_size") try: if flash_used is None: + _LOGGER.debug( + "No total_size in %s, deriving from %s", size_json, firmware_elf + ) flash_used = _image_size_from_elf(firmware_elf) app_size = _find_app_partition_size(partitions_csv) except FileNotFoundError as e: diff --git a/tests/unit_tests/test_size_summary.py b/tests/unit_tests/test_size_summary.py index 593aa8cc4f..cebf16eca5 100644 --- a/tests/unit_tests/test_size_summary.py +++ b/tests/unit_tests/test_size_summary.py @@ -214,6 +214,8 @@ _GOOD_ELF = _elf_bytes([(1, 0x2, 1024)]) _elf_bytes([(1, 0x2, 1024)], shentsize=0), True, id="bad_shentsize" ), pytest.param(_GOOD_ELF[:60], True, id="truncated_table"), + pytest.param(_elf_bytes([]), True, id="no_sections"), + pytest.param(_elf_bytes([(8, 0x2, 50000)]), True, id="no_progbits"), pytest.param(_GOOD_ELF, False, id="missing_partitions"), ], )