]> git.ipfire.org Git - thirdparty/linux.git/blobdiff - fs/erofs/zmap.c
Merge tag 'erofs-for-6.8-rc1-fixes' of git://git.kernel.org/pub/scm/linux/kernel...
[thirdparty/linux.git] / fs / erofs / zmap.c
index 9753875e41cb35a4e83468aafb885f71a4bb1547..e313c936351d51fb39685702437d22bbef16719a 100644 (file)
@@ -454,7 +454,7 @@ static int z_erofs_do_map_blocks(struct inode *inode,
                .map = map,
        };
        int err = 0;
-       unsigned int lclusterbits, endoff;
+       unsigned int lclusterbits, endoff, afmt;
        unsigned long initial_lcn;
        unsigned long long ofs, end;
 
@@ -543,17 +543,20 @@ static int z_erofs_do_map_blocks(struct inode *inode,
                        err = -EFSCORRUPTED;
                        goto unmap_out;
                }
-               if (vi->z_advise & Z_EROFS_ADVISE_INTERLACED_PCLUSTER)
-                       map->m_algorithmformat =
-                               Z_EROFS_COMPRESSION_INTERLACED;
-               else
-                       map->m_algorithmformat =
-                               Z_EROFS_COMPRESSION_SHIFTED;
-       } else if (m.headtype == Z_EROFS_LCLUSTER_TYPE_HEAD2) {
-               map->m_algorithmformat = vi->z_algorithmtype[1];
+               afmt = vi->z_advise & Z_EROFS_ADVISE_INTERLACED_PCLUSTER ?
+                       Z_EROFS_COMPRESSION_INTERLACED :
+                       Z_EROFS_COMPRESSION_SHIFTED;
        } else {
-               map->m_algorithmformat = vi->z_algorithmtype[0];
+               afmt = m.headtype == Z_EROFS_LCLUSTER_TYPE_HEAD2 ?
+                       vi->z_algorithmtype[1] : vi->z_algorithmtype[0];
+               if (!(EROFS_I_SB(inode)->available_compr_algs & (1 << afmt))) {
+                       erofs_err(inode->i_sb, "inconsistent algorithmtype %u for nid %llu",
+                                 afmt, vi->nid);
+                       err = -EFSCORRUPTED;
+                       goto unmap_out;
+               }
        }
+       map->m_algorithmformat = afmt;
 
        if ((flags & EROFS_GET_BLOCKS_FIEMAP) ||
            ((flags & EROFS_GET_BLOCKS_READMORE) &&