- Expected result:
- cur = 0
- Actual result:
- cur = 0x370
Signed-off-by: Chunhai Guo <[email protected]>
---
fs/erofs/zdata.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c
index 5f1890e309c6..6abbd4510076 100644
--- a/fs/erofs/zdata.c
+++ b/fs/erofs/zdata.c
@@ -972,7 +972,8 @@ static int z_erofs_do_read_page(struct
z_erofs_decompress_frontend *fe,
struct erofs_map_blocks *const map = &fe->map;
const loff_t offset = page_offset(page);
bool tight = true, exclusive;
- unsigned int cur, end, spiltted;
+ erofs_off_t cur, end;
+ unsigned int spiltted;
int err = 0;
/* register locked file pages as online pages in pack */
@@ -1035,7 +1036,7 @@ static int z_erofs_do_read_page(struct
z_erofs_decompress_frontend *fe,
*/
tight &= (fe->mode > Z_EROFS_PCLUSTER_FOLLOWED_NOINPLACE);
- cur = end - min_t(unsigned int, offset + end - map->m_la, end);
+ cur = end - min_t(erofs_off_t, offset + end - map->m_la, end);
if (!(map->m_flags & EROFS_MAP_MAPPED)) {
zero_user_segment(page, cur, end);
goto next_part;
@@ -1841,7 +1842,7 @@ static void z_erofs_pcluster_readmore(struct
z_erofs_decompress_frontend *f,
}
cur = map->m_la + map->m_llen - 1;
- while (cur >= end) {
+ while ((cur >= end) && (cur < i_size_read(inode))) {
pgoff_t index = cur >> PAGE_SHIFT;
struct page *page;
@@ -1876,6 +1877,12 @@ static int z_erofs_read_folio(struct file *file, struct folio *folio)
trace_erofs_readpage(page, false);
f.headoffset = (erofs_off_t)page->index << PAGE_SHIFT;
+ /* when trying to read beyond EOF, return zero page directly */
+ if (f.headoffset >= i_size_read(inode)) {
+ zero_user_segment(page, 0, PAGE_SIZE);
+ return 0;
+ }