From: Gao Xiang <hsiangkao@linux.alibaba.com>
To: linux-erofs@lists.ozlabs.org
Cc: Gao Xiang <hsiangkao@linux.alibaba.com>
Subject: [PATCH] erofs-utils: tar: fix overly large size in tar header
Date: Thu, 16 Jul 2026 11:24:01 +0800 [thread overview]
Message-ID: <20260716032401.4172874-1-hsiangkao@linux.alibaba.com> (raw)
As @oscarjhk reported:
When tar-index mode is used, the inode chunk count will be calculated
as 0 if a crafted GNU base-256 size is UINT64_MAX, which will cause
a heap out-of-bounds write.
Fixes: 95d315fd7958 ("erofs-utils: introduce tarerofs")
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
lib/blobchunk.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lib/blobchunk.c b/lib/blobchunk.c
index 0523873570a2..5e0fb70be687 100644
--- a/lib/blobchunk.c
+++ b/lib/blobchunk.c
@@ -507,7 +507,9 @@ int tarerofs_write_chunkes(struct erofs_inode *inode, erofs_off_t data_offset)
datablob_size += round_up(inode->i_size, erofs_blksiz(sbi));
}
chunksize = 1ULL << chunkbits;
- count = DIV_ROUND_UP(inode->i_size, chunksize);
+ /* e.g. DIV_ROUND_UP(UINT64_MAX, 1 TiB) can overflow */
+ count = (inode->i_size >> chunkbits) +
+ !!(inode->i_size & (chunksize - 1));
inode->extent_isize = count * unit;
idx = calloc(count, max(sizeof(*idx), sizeof(void *)));
--
2.43.5
next reply other threads:[~2026-07-16 3:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-16 3:24 Gao Xiang [this message]
2026-07-17 3:04 ` [PATCH] erofs-utils: tar: refuse negative size in tar header Gao Xiang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260716032401.4172874-1-hsiangkao@linux.alibaba.com \
--to=hsiangkao@linux.alibaba.com \
--cc=linux-erofs@lists.ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox