Skip to contentSkip to conversation

cramfs: fix direct uncompressed full-page reads

PATCH New Yichong Chen 1 participant 1 message Sep 3 Cramfs filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cramfs: fix direct uncompressed full-page reads

For direct uncompressed cramfs blocks, the block size is PAGE_SIZE except for the last block, where it is capped by the file size.

When the file size is exactly page-aligned, offset_in_page(i_size) returns 0. The current last-block handling then turns the final full page into a zero-length block, so cramfs_read_folio() treats it as a hole and returns zero-filled data instead of the stored page.

Keep PAGE_SIZE for a page-aligned final block, and only shorten the block when the last page is partial.

Fixes fd4f6f2a78ae ("cramfs: implement uncompressed and arbitrary data block positioning")
---
 fs/cramfs/inode.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/cramfs/inode.c +3 -3
index d4cd03f4f60d..371b4c421d86 100644
@@ -853,9 +853,9 @@ static int cramfs_read_folio(struct file *file, struct folio *folio)
 			if (uncompressed) {
 				block_len = PAGE_SIZE;
 				/* if last block: cap to file length */
-				if (folio->index == maxblock - 1)
-					block_len =
-						offset_in_page(inode->i_size);
+				if (folio->index == maxblock - 1 &&
+				    offset_in_page(inode->i_size))
+					block_len = offset_in_page(inode->i_size);
 			} else {
 				block_len = *(u16 *)
 					cramfs_read(sb, block_start, 2);
Signature · 1 line
2.51.0