-@@ -287,10 +296,19 @@ void receive_xattr(struct file_struct *f
- out_of_memory("receive_xattr");
- read_buf(f, ptr, name_len);
- read_buf(f, ptr + name_len, datum_len);
-+
-+ if (am_root < 0 && name_len == sizeof FAKE_XATTR
-+ && ptr[10] == '%' && strcmp(ptr, FAKE_XATTR) == 0) {
+@@ -176,6 +185,13 @@ static int rsync_xal_get(const char *fna
+ return -1;
+ }
+ }
++#ifdef HAVE_LINUX_XATTRS
++ if (am_root < 0 && name_len > RPRE_LEN
++ && HAS_PREFIX(name, RSYNC_PREFIX)) {
++ name += RPRE_LEN;
++ name_len -= RPRE_LEN;
++ }
++#endif
+ rxas = EXPAND_ITEM_LIST(xalp, rsync_xa, RSYNC_XAL_INITIAL);
+ rxas->name = ptr + datum_len;
+ rxas->datum = ptr;
+@@ -296,13 +312,9 @@ void receive_xattr(struct file_struct *f
+ rsync_xa *rxa;
+ size_t name_len = read_int(f);
+ size_t datum_len = read_int(f);
+-#ifdef HAVE_LINUX_XATTRS
+- size_t extra_len = 0;
+-#else
+- size_t extra_len = am_root ? RPRE_LEN : 0;
++ size_t extra_len = MIGHT_NEED_RPRE ? RPRE_LEN : 0;
+ if (datum_len + extra_len < datum_len)
+ out_of_memory("receive_xattr"); /* overflow */
+-#endif
+ if (name_len + datum_len + extra_len < name_len)
+ out_of_memory("receive_xattr"); /* overflow */
+ ptr = new_array(char, name_len + datum_len + extra_len);
+@@ -313,9 +325,14 @@ void receive_xattr(struct file_struct *f
+ read_buf(f, ptr, datum_len);
+ #ifdef HAVE_LINUX_XATTRS
+ /* Non-root can only save the user namespace. */
+- if (!am_root && !HAS_PREFIX(name, USER_PREFIX)) {
+- free(ptr);
+- continue;
++ if (am_root <= 0 && !HAS_PREFIX(name, USER_PREFIX)) {
++ if (!am_root) {
++ free(ptr);
++ continue;
++ }
++ name -= RPRE_LEN;
++ name_len += RPRE_LEN;
++ memcpy(name, RSYNC_PREFIX, RPRE_LEN);
+ }
+ #else
+ /* This OS only has a user namespace, so we either
+@@ -333,6 +350,12 @@ void receive_xattr(struct file_struct *f
+ continue;
+ }
+ #endif
++ if (am_root < 0 && name_len == XSTAT_LEN + 1
++ && name[RPRE_LEN] == '%'
++ && strcmp(name, XSTAT_ATTR) == 0) {