diff mbox series

[2/4] cpio_utils: fill_buffer: fix return value on EOF after short read

Message ID 20240617072905.2275940-3-dominique.martinet@atmark-techno.com
State Accepted
Headers show
Series misc fixes from chunked stream rework | expand

Commit Message

Dominique Martinet June 17, 2024, 7:29 a.m. UTC
fill_buffer would return 0 after having filled buffer/updated checksums
if it reaches the end of file (returns 0) after another read.

In practice, this never happens because the caller knows how much to
read, and chunks are smaller than what had been previously written in
the pipe so this is a theorical problem, but because the checksums are
correctly updated until the end this would not be detected if it happens
in practice (the end of the data would just not be fed to the handler),
so this is best fixed.

Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
---
 core/cpio_utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Stefano Babic June 18, 2024, 8:56 p.m. UTC | #1
Hi Dominique,

On 17.06.24 09:29, Dominique Martinet wrote:
> fill_buffer would return 0 after having filled buffer/updated checksums
> if it reaches the end of file (returns 0) after another read.
>
> In practice, this never happens because the caller knows how much to
> read, and chunks are smaller than what had been previously written in
> the pipe so this is a theorical problem,

Yes, if it happens, there some bug somewhere else because the caller
passes the size. Anyway, it is not bad to fix it.

> but because the checksums are
> correctly updated until the end this would not be detected if it happens
> in practice (the end of the data would just not be fed to the handler),
> so this is best fixed.
>
> Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
> ---
>   core/cpio_utils.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/core/cpio_utils.c b/core/cpio_utils.c
> index 00b15f030c74..6178fedca216 100644
> --- a/core/cpio_utils.c
> +++ b/core/cpio_utils.c
> @@ -73,7 +73,7 @@ static int _fill_buffer(int fd, unsigned char *buf, unsigned int nbytes, unsigne
>   			return -EFAULT;
>   		}
>   		if (len == 0) {
> -			return 0;
> +			return count;
>   		}
>   		if (checksum)
>   			for (i = 0; i < len; i++)

Acked-by: Stefano Babic <stefano.babic@swupdate.org>
diff mbox series

Patch

diff --git a/core/cpio_utils.c b/core/cpio_utils.c
index 00b15f030c74..6178fedca216 100644
--- a/core/cpio_utils.c
+++ b/core/cpio_utils.c
@@ -73,7 +73,7 @@  static int _fill_buffer(int fd, unsigned char *buf, unsigned int nbytes, unsigne
 			return -EFAULT;
 		}
 		if (len == 0) {
-			return 0;
+			return count;
 		}
 		if (checksum)
 			for (i = 0; i < len; i++)