[PATCH] erofs-utils: lib: fix EINTR mishandling in erofs_io_read()
Utkal Singh
singhutkal015 at gmail.com
Mon Mar 30 07:44:24 AEDT 2026
Subject: Re: [PATCH] erofs-utils: lib: fix EINTR mishandling in erofs_io_read()
On Sat, Mar 28, 2026 at 6:51 PM, Ajay Rajera wrote:
> Fix this by setting ret to 0 on EINTR before falling through,
> matching the existing pattern in __erofs_io_write() and erofs_io_pread().
Hi Ajay,
The fix is correct. Placing ret = 0 after the inner if-else is safe
because the else branch always returns, so the assignment is only
reachable on EINTR. It correctly handles the partial-read case too:
After a short read advances i and decrements bytes, a subsequent EINTR
leaves both unchanged via ret = 0 and the retry continues from the
right buffer position.
Reviewed-by: Utkal Singh <singhutkal015 at gmail.com>
On Sat, 28 Mar 2026 at 18:51, Ajay Rajera <newajay.11r at gmail.com> wrote:
>
> When read() is interrupted by a signal and returns -1 with
> errno == EINTR, erofs_io_read() falls through without zeroing
> ret. This causes `bytes -= ret` and `i += ret` to execute with
> ret == -1, corrupting the byte counter (bytes wraps around since
> it is size_t) and the offset. This can lead to incorrect reads
> or infinite loops.
>
> Fix this by setting ret to 0 on EINTR before falling through,
> matching the existing pattern in __erofs_io_write() and
> erofs_io_pread().
>
> Also fix inconsistent whitespace (spaces instead of tabs) on the
> closing brace and return statement.
>
> Signed-off-by: Ajay Rajera <newajay.11r at gmail.com>
> ---
> lib/io.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/lib/io.c b/lib/io.c
> index 0c5eb2c..dd5e304 100644
> --- a/lib/io.c
> +++ b/lib/io.c
> @@ -551,11 +551,12 @@ ssize_t erofs_io_read(struct erofs_vfile *vf, void *buf, size_t bytes)
> strerror(errno));
> return -errno;
> }
> + ret = 0;
> }
> bytes -= ret;
> i += ret;
> - }
> - return i;
> + }
> + return i;
> }
>
> ssize_t erofs_io_write(struct erofs_vfile *vf, void *buf, size_t len)
> --
> 2.51.0.windows.1
>
>
More information about the Linux-erofs
mailing list