From: Yue Hu <[email protected]>

Keep in sync with kernel commit 24331050a3e6 ("erofs: fix small
compressed files inlining") to avoid corruption due to m_llen > m_plen
for uncompressed pclusters.

Fixes: 41790d24329d ("erofs-utils: validate the extent length for uncompressed 
pclusters")
Signed-off-by: Yue Hu <[email protected]>
---
 lib/zmap.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lib/zmap.c b/lib/zmap.c
index 7492e5d..209b5d7 100644
--- a/lib/zmap.c
+++ b/lib/zmap.c
@@ -597,6 +597,13 @@ static int z_erofs_do_map_blocks(struct erofs_inode *vi,
                if (endoff >= m.clusterofs) {
                        m.headtype = m.type;
                        map->m_la = (m.lcn << lclusterbits) | m.clusterofs;
+                       /*
+                        * For ztailpacking files, in order to inline data more
+                        * effectively, special EOF lclusters are now supported
+                        * which can have three parts at most.
+                        */
+                       if (ztailpacking && end > vi->i_size)
+                               end = vi->i_size;
                        break;
                }
                /* m.lcn should be >= 1 if endoff < m.clusterofs */
-- 
2.17.1

Reply via email to