Don't output more than 255 shared xattrs for a single inode due to the
EROFS on-disk format limitation.

Fixes: 116ac0a254fc ("erofs-utils: introduce shared xattr support")
Signed-off-by: Gao Xiang <[email protected]>
---
 lib/xattr.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/xattr.c b/lib/xattr.c
index 790547c..1ed796b 100644
--- a/lib/xattr.c
+++ b/lib/xattr.c
@@ -665,6 +665,7 @@ int erofs_prepare_xattr_ibody(struct erofs_inode *inode)
        int ret;
        struct inode_xattr_node *node;
        struct list_head *ixattrs = &inode->i_xattrs;
+       unsigned int h_shared_count;
 
        if (list_empty(ixattrs)) {
                inode->xattr_isize = 0;
@@ -672,11 +673,13 @@ int erofs_prepare_xattr_ibody(struct erofs_inode *inode)
        }
 
        /* get xattr ibody size */
+       h_shared_count = 0;
        ret = sizeof(struct erofs_xattr_ibody_header);
        list_for_each_entry(node, ixattrs, list) {
                struct xattr_item *item = node->item;
 
-               if (item->shared_xattr_id >= 0) {
+               if (item->shared_xattr_id >= 0 || h_shared_count < UCHAR_MAX) {
+                       ++h_shared_count;
                        ret += sizeof(__le32);
                        continue;
                }
@@ -980,7 +983,8 @@ char *erofs_export_xattr_ibody(struct erofs_inode *inode)
                list_del(&node->list);
 
                /* move inline xattrs to the onstack list */
-               if (item->shared_xattr_id < 0) {
+               if (item->shared_xattr_id < 0 ||
+                   header->h_shared_count >= UCHAR_MAX) {
                        list_add(&node->list, &ilst);
                        continue;
                }
-- 
2.39.3

Reply via email to