[PATCH] erofs-utils: lib: fix EINTR mishandling in erofs_io_read()

Ajay Rajera newajay.11r at gmail.com
Sun Mar 29 00:20:46 AEDT 2026


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