From c180703603f314ef83c39aae5a15c83c72918a64 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Tue, 18 Mar 2025 01:58:27 +0100 Subject: ext2fs: Do not try to frob inline data for regular files and directories Inline data in i_data is only used by symlinks (and apparently some device nodes in linux). For regular files and directories we don't store data there. This is actually important since otherwise int fd = open("foo.txt", O_WRONLY|O_CREAT); ftruncate(fd, 1024); ftruncate(fd, 10); leads to trying to frob beyond i_data end. --- ext2fs/truncate.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'ext2fs/truncate.c') diff --git a/ext2fs/truncate.c b/ext2fs/truncate.c index 44aab3c7..aa3a5a60 100644 --- a/ext2fs/truncate.c +++ b/ext2fs/truncate.c @@ -291,7 +291,9 @@ diskfs_truncate (struct node *node, off_t length) if (length >= node->dn_stat.st_size) return 0; - if (! node->dn_stat.st_blocks) + if (! node->dn_stat.st_blocks + && !S_ISREG (node->dn_stat.st_mode) + && !S_ISDIR (node->dn_stat.st_mode)) /* There aren't really any blocks allocated, so just frob the size. This is true for fast symlinks, and also apparently for some device nodes in linux. */ -- cgit v1.2.3