[PATCH v2] erofs-utils: lib: validate algorithm for encoded extents
Utkal Singh
singhutkal015 at gmail.com
Mon Mar 16 01:22:49 AEDT 2026
Encoded extents use fmt field as algorithm index without checking
available_compr_algs bitmask. The non-encoded path already has this
check but the encoded extent path in z_erofs_map_blocks_ext() was
missing equivalent validation.
Add available_compr_algs consistency check for encoded extents,
following kernel commit 131897c65e2b.
Signed-off-by: Utkal Singh <singhutkal015 at gmail.com>
---
lib/zmap.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/lib/zmap.c b/lib/zmap.c
index 0e7af4e..a8d1ca6 100644
--- a/lib/zmap.c
+++ b/lib/zmap.c
@@ -630,8 +630,17 @@ static int z_erofs_map_blocks_ext(struct erofs_inode *vi,
if (map->m_plen & Z_EROFS_EXTENT_PLEN_PARTIAL)
map->m_flags |= EROFS_MAP_PARTIAL_REF;
map->m_plen &= Z_EROFS_EXTENT_PLEN_MASK;
- if (fmt)
- map->m_algorithmformat = fmt - 1;
+ if (fmt) {
+ unsigned int afmt = fmt - 1;
+
+ if (afmt >= Z_EROFS_COMPRESSION_MAX ||
+ !(sbi->available_compr_algs & (1 << afmt))) {
+ erofs_err("unknown algorithm %u for encoded extent, nid %llu",
+ afmt, vi->nid | 0ULL);
+ return -EOPNOTSUPP;
+ }
+ map->m_algorithmformat = afmt;
+ }
else if (interlaced && !((map->m_pa | map->m_plen) & bmask))
map->m_algorithmformat =
Z_EROFS_COMPRESSION_INTERLACED;
--
2.43.0
More information about the Linux-erofs
mailing list