[PATCH U-BOOT 3/3] btrfs: btfs_file_read: zero trailing data if no extent was found

Dominique Martinet asmadeus at codewreck.org
Tue Apr 18 03:17:35 CEST 2023


From: Dominique Martinet <dominique.martinet at atmark-techno.com>

btfs_file_read's truncate path has a comment noting '>0 means no extent'
and bailing out immediately, but the buffer has not been written so
probably needs zeroing out.

This is a theorical fix only and hasn't been tested on a file that
actually runs this code path.

Signed-off-by: Dominique Martinet <dominique.martinet at atmark-techno.com>
---
 fs/btrfs/inode.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index efffec0f2e68..23c006c98c3b 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -756,9 +756,12 @@ int btrfs_file_read(struct btrfs_root *root, u64 ino, u64 file_offset, u64 len,
 		btrfs_release_path(&path);
 		ret = lookup_data_extent(root, &path, ino, cur,
 					 &next_offset);
-		/* <0 is error, >0 means no extent */
-		if (ret)
+		/* <0 is error, >0 means no extent: zero end of buffer */
+		if (ret) {
+			if (ret > 0)
+				memset(dest + cur, 0, end - cur);
 			goto out;
+		}
 		fi = btrfs_item_ptr(path.nodes[0], path.slots[0],
 				    struct btrfs_file_extent_item);
 		ret = read_and_truncate_page(&path, fi, cur,

-- 
2.39.2



More information about the U-Boot mailing list