[PATCH v1 11/13] ntfs: stop compressed reads at EOF within a base page

From: Baolin Liu

Date: Wed Dec 02 2026 - 23:07:40 EST


From: Baolin Liu <liubaolin@xxxxxxxxxx>

With 64 KiB base pages and 512-byte clusters, a page contains eight 8 KiB
compression units. If EOF precedes the end of the page, cur_page does
not reach max_page. The reader then accesses compression units beyond
EOF and can return EIO when their runlist mapping is absent. This also
affects order-0 folios.

Stop after the compression unit containing the last file byte. If it
leaves a partial base page, zero the remainder and complete that page
before finishing the target folio. Preserve errors for missing mappings
within the file.

Fixes: 1e9ea7e04472 ("Revert "fs: Remove NTFS classic"")
Signed-off-by: Baolin Liu <liubaolin@xxxxxxxxxx>
---
fs/ntfs/compress.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/fs/ntfs/compress.c b/fs/ntfs/compress.c
index 0f41591db1b5..1fff4fee7849 100644
--- a/fs/ntfs/compress.c
+++ b/fs/ntfs/compress.c
@@ -769,9 +769,20 @@ lock_retry_remap:
}

/* Stop at EOF even if the target folio spans more compression units. */
- if (nr_cbs && cur_page < max_page)
+ if (nr_cbs && cur_page < max_page &&
+ ntfs_cluster_to_bytes(vol, start_vcn) < i_size)
goto do_next_cb;

+ /* EOF can precede the end of a base page when cb_size < PAGE_SIZE. */
+ if (cur_ofs && cur_page < max_page) {
+ page = pages[cur_page];
+ if (page) {
+ zero_user_segment(page, cur_ofs, PAGE_SIZE);
+ ntfs_end_compressed_page(pages, cur_page, folio,
+ &nr_completed, i_size, initialized_size);
+ }
+ }
+
out:
/* Only neighbouring pages hold references acquired by this read. */
for (i = 0; i < max_page; i++) {