erofs-utils: fsck: extract chunk-based file with hole correctly
authorYifan Zhao <zhaoyifan@sjtu.edu.cn>
Mon, 22 Apr 2024 11:31:32 +0000 (19:31 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Wed, 24 Apr 2024 10:46:56 +0000 (18:46 +0800)
Currently fsck skips file extraction if it finds that EROFS_MAP_MAPPED
is unset, which is not the case for chunk-based files with holes.

This patch handles the corner case correctly.

Signed-off-by: Yifan Zhao <zhaoyifan@sjtu.edu.cn>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
fsck/main.c

index e5c37bea7b8f871ea036cd1832f8c97a676bfbd2..4dcb49d8d571ce16647983ecfd8bc661dcf9cf57 100644 (file)
@@ -470,9 +470,18 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd)
                pos += map.m_llen;
 
                /* should skip decomp? */
-               if (!(map.m_flags & EROFS_MAP_MAPPED) || !fsckcfg.check_decomp)
+               if (map.m_la >= inode->i_size || !fsckcfg.check_decomp)
                        continue;
 
+               if (outfd >= 0 && !(map.m_flags & EROFS_MAP_MAPPED)) {
+                       ret = lseek(outfd, map.m_llen, SEEK_CUR);
+                       if (ret < 0) {
+                               ret = -errno;
+                               goto out;
+                       }
+                       continue;
+               }
+
                if (map.m_plen > Z_EROFS_PCLUSTER_MAX_SIZE) {
                        if (compressed) {
                                erofs_err("invalid pcluster size %" PRIu64 " @ offset %" PRIu64 " of nid %" PRIu64,