diff
1 static esp_err_t process_segment_data(intptr_t load_addr, uint32_t data_addr, uint32_t data_len, bool do_load, bootloader_sha256_handle_t sha_handle, uint32_t *checksum) {
+   size_t allocated_size = /* retrieve the size of memory allocated at load_addr */;
+   if (data_len > allocated_size) {
+       return ESP_ERR_INVALID_SIZE;
+   }
    // ... rest of the function ...
}
