[PATCH 2/2] fs/ntfs3: do not require compression unit 0 in later attribute segments

From: Ernest Borowski via B4 Relay

Date: Fri Dec 04 2026 - 16:31:34 EST


From: Ernest Borowski <ernest.borowski.git@xxxxxxxxx>

mi_enum_attr() requires the compression unit of every non-resident
attribute segment except the first one of a sparse or compressed
attribute to be 0. ntfs-3g (libntfs ntfs_non_resident_attr_record_add())
writes the standard compression unit (4) into every segment of a
compressed attribute, so a compressed file whose runs no longer fit in
one MFT record cannot be read by ntfs3:

ntfs3(loop0): ino=7011, mi_enum_attr

and every read returns -EINVAL, while ntfs-3g, the ntfs driver and
ntfsck read and check the file fine. Before commit 2afd4d267e6d
("fs/ntfs3: Mark inode as bad as soon as error detected in
mi_enum_attr()") the segment was silently skipped instead.

ntfs3 never uses the compression unit of a later segment.
attr_is_frame_compressed() and the other users take it from the first
segment. Check it only in the first segment of an attribute that is
neither sparse nor compressed.

Reproduced on a 64 MiB volume with 512-byte clusters and fragmented free
space: ntfs-3g writes a 3 MB compressible file into a compressed
directory; its $DATA takes three MFT records, all with compression unit
4.

Fixes: 4342306f0f0d ("fs/ntfs3: Add file operations and implementation")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Ernest Borowski <ernest.borowski.git@xxxxxxxxx>
---
fs/ntfs3/record.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/ntfs3/record.c b/fs/ntfs3/record.c
index 7669db5314..16c22e2bb0 100644
--- a/fs/ntfs3/record.c
+++ b/fs/ntfs3/record.c
@@ -381,7 +381,12 @@ struct ATTRIB *mi_enum_attr(struct ntfs_inode *ni, struct mft_inode *mi,
if (tot_size > alloc_size)
goto out;
} else {
- if (attr->nres.c_unit)
+ /*
+ * Only the compression unit of the first segment is used.
+ * ntfs-3g also stores it in the later segments of a compressed
+ * attribute, so do not insist on 0 there.
+ */
+ if (!svcn && attr->nres.c_unit)
goto out;

if (alloc_size > mi->sbi->volume.size)

--
2.56.1