[PATCH 1/3] erofs-utils: lib: fix improper alignment for chunked sparse files

Gao Xiang hsiangkao at linux.alibaba.com
Tue Jul 25 03:06:44 AEST 2023


File position should be fixed to aligned with the chunk boundary.
Otherwise, incorrect data could be read.

Fixes: 7c49e8b195ad ("erofs-utils: support chunk-based sparse files")
Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
 lib/blobchunk.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/blobchunk.c b/lib/blobchunk.c
index 44541d5..c0df2f7 100644
--- a/lib/blobchunk.c
+++ b/lib/blobchunk.c
@@ -228,8 +228,12 @@ int erofs_blob_write_chunked_file(struct erofs_inode *inode, int fd)
 				offset = pos;
 			else
 				offset = ((pos >> chunkbits) + 1) << chunkbits;
-		} else {
+		} else if (offset != (offset & ~(chunksize - 1))) {
 			offset &= ~(chunksize - 1);
+			if (lseek(fd, offset, SEEK_SET) != offset) {
+				ret = -EIO;
+				goto err;
+			}
 		}
 
 		if (offset > pos) {
-- 
2.24.4



More information about the Linux-erofs mailing list