This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit caa47f282ead6f4f923f6a6d00e738fcbb8979a5 Author: wangjianyu3 <[email protected]> AuthorDate: Mon Aug 5 16:33:55 2024 +0800 system/fastboot: Fix that `total_chunks` of sparse_header maybe error when size of image passed to command "fastboot flash" is not 4KB aligned. Signed-off-by: wangjianyu3 <[email protected]> --- system/fastboot/fastboot.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/fastboot/fastboot.c b/system/fastboot/fastboot.c index 57dcf5050..2041dfee6 100644 --- a/system/fastboot/fastboot.c +++ b/system/fastboot/fastboot.c @@ -362,6 +362,7 @@ static int fastboot_flash_program(FAR struct fastboot_ctx_s *context, int fd) { FAR char *chunk_ptr = context->download_buffer; + FAR char *end_ptr = chunk_ptr + context->download_size; FAR struct fastboot_sparse_header_s *sparse; uint32_t chunk_num; int ret = OK; @@ -382,10 +383,9 @@ fastboot_flash_program(FAR struct fastboot_ctx_s *context, int fd) } chunk_num = sparse->total_chunks; - chunk_ptr += FASTBOOT_SPARSE_HEADER; - while (chunk_num--) + while (chunk_ptr < end_ptr && chunk_num--) { FAR struct fastboot_chunk_header_s *chunk = (FAR struct fastboot_chunk_header_s *)chunk_ptr;
