[PATCH] erofs-utils: lib: restrict pcluster size limitations
Gao Xiang
hsiangkao at linux.alibaba.com
Mon Feb 10 01:38:08 AEDT 2025
Source kernel commit: 7c3ca1838a7831855cbf2e6927a10e0e4723edf6
Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
include/erofs_fs.h | 5 ++++-
lib/zmap.c | 41 ++++++++++++++++++++---------------------
2 files changed, 24 insertions(+), 22 deletions(-)
diff --git a/include/erofs_fs.h b/include/erofs_fs.h
index 5672c99..269d302 100644
--- a/include/erofs_fs.h
+++ b/include/erofs_fs.h
@@ -297,9 +297,12 @@ enum {
#define EROFS_NAME_LEN 255
-/* maximum supported size of a physical compression cluster */
+/* maximum supported encoded size of a physical compressed cluster */
#define Z_EROFS_PCLUSTER_MAX_SIZE (1024 * 1024)
+/* maximum supported decoded size of a physical compressed cluster */
+#define Z_EROFS_PCLUSTER_MAX_DSIZE (12 * 1024 * 1024)
+
/* available compression algorithm types (for h_algorithmtype) */
enum {
Z_EROFS_COMPRESSION_LZ4 = 0,
diff --git a/lib/zmap.c b/lib/zmap.c
index b84d214..70ff898 100644
--- a/lib/zmap.c
+++ b/lib/zmap.c
@@ -633,30 +633,29 @@ int z_erofs_map_blocks_iter(struct erofs_inode *vi,
{
int err = 0;
- /* when trying to read beyond EOF, leave it unmapped */
- if (map->m_la >= vi->i_size) {
+ if (map->m_la >= vi->i_size) { /* post-EOF unmapped extent */
map->m_llen = map->m_la + 1 - vi->i_size;
map->m_la = vi->i_size;
map->m_flags = 0;
- goto out;
- }
-
- err = z_erofs_fill_inode_lazy(vi);
- if (err)
- goto out;
-
- if ((vi->z_advise & Z_EROFS_ADVISE_FRAGMENT_PCLUSTER) &&
- !vi->z_tailextent_headlcn) {
- map->m_la = 0;
- map->m_llen = vi->i_size;
- map->m_flags = EROFS_MAP_MAPPED | EROFS_MAP_FULL_MAPPED |
- EROFS_MAP_FRAGMENT;
- goto out;
+ } else {
+ err = z_erofs_fill_inode_lazy(vi);
+ if (!err) {
+ if ((vi->z_advise & Z_EROFS_ADVISE_FRAGMENT_PCLUSTER) &&
+ !vi->z_tailextent_headlcn) {
+ map->m_la = 0;
+ map->m_llen = vi->i_size;
+ map->m_flags = EROFS_MAP_MAPPED |
+ EROFS_MAP_FULL_MAPPED | EROFS_MAP_FRAGMENT;
+ } else {
+ err = z_erofs_do_map_blocks(vi, map, flags);
+ }
+ }
+ if (!err && (map->m_flags & EROFS_MAP_ENCODED) &&
+ __erofs_unlikely(map->m_plen > Z_EROFS_PCLUSTER_MAX_SIZE ||
+ map->m_llen > Z_EROFS_PCLUSTER_MAX_DSIZE))
+ err = -EOPNOTSUPP;
+ if (err)
+ map->m_llen = 0;
}
-
- err = z_erofs_do_map_blocks(vi, map, flags);
-out:
- if (err)
- map->m_llen = 0;
return err;
}
--
2.43.5
More information about the Linux-erofs
mailing list