Skip to contentSkip to conversation

erofs-utils: lib: handle unexpected EOF in erofs_io_xcopy()

PATCH New Vansh Choudhary 1 participant 1 message Apr 9 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 erofs-utils: lib: handle unexpected EOF in erofs_io_xcopy()

Treat a zero-length read from erofs_io_read() as an I/O failure when erofs_io_xcopy() still has data left to copy.

Without that, the copy loop makes no forward progress after an early EOF and can spin indefinitely.

---
 lib/io.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
lib/io.c +6 -6
index 0c5eb2c..80b7639 100644
@@ -667,12 +667,12 @@ int erofs_io_xcopy(struct erofs_vfile *vout, off_t pos,
 		ret = erofs_io_read(vin, buf, ret);
 		if (ret < 0)
 			return ret;
-		if (ret > 0) {
-			ret = erofs_io_pwrite(vout, buf, pos, ret);
-			if (ret < 0)
-				return ret;
-			pos += ret;
-		}
+		if (!ret)
+			return -EIO;
+		ret = erofs_io_pwrite(vout, buf, pos, ret);
+		if (ret < 0)
+			return ret;
+		pos += ret;
 		len -= ret;
 	} while (len);
 	return 0;
Signature · 1 line
2.43.0