From 9c608021f8a5135aab9efc97e371737832c0f3de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Sun, 7 May 2023 22:38:36 +0200 Subject: [PATCH] image: Fix image_read() function when image has padding --- src/image.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/image.c b/src/image.c index 37fa32f..234329e 100644 --- a/src/image.c +++ b/src/image.c @@ -528,13 +528,16 @@ size_t image_read(struct image * image, void * buf, size_t count) { } - if ( image_fd->align > 0 && count > 0 ) { + if ( image_fd->align > 0 && count > 0 && image->cur < start + image_fd->size ) { if ( count > image_fd->align ) new_count = image_fd->align; else new_count = count; + if ( image->cur + new_count > start + image_fd->size ) + new_count = start + image_fd->size - image->cur; + memset(buf, 0xFF, new_count); ret = new_count;