From: Zhan Xusheng <zhanxusheng1024@gmail.com>
To: Gao Xiang <hsiangkao@linux.alibaba.com>
Cc: linux-erofs@lists.ozlabs.org, Zhan Xusheng <zhanxusheng@xiaomi.com>
Subject: [PATCH 2/2] erofs-utils: tar: add missing NULL checks for GNU long name/link
Date: Tue, 14 Apr 2026 22:13:13 +0800 [thread overview]
Message-ID: <20260414141313.46575-3-zhanxusheng@xiaomi.com> (raw)
In-Reply-To: <20260414141313.46575-1-zhanxusheng@xiaomi.com>
In the GNU long name ('L') and long link ('K') handling, malloc()
return values are not checked. If st.st_size is excessively large
from a crafted tar header, malloc() fails and returns NULL, then
erofs_iostream_bread() writes to a NULL pointer causing a crash.
Also add the missing PATH_MAX bound check for 'L' entries, which
the 'K' path already had.
Fixes: 95d315fd7958 ("erofs-utils: introduce tarerofs")
Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
---
lib/tar.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/lib/tar.c b/lib/tar.c
index 3d92f48..24d8314 100644
--- a/lib/tar.c
+++ b/lib/tar.c
@@ -886,7 +886,8 @@ out_eot:
case 'L':
free(eh.path);
eh.path = malloc(st.st_size + 1);
- if (st.st_size != erofs_iostream_bread(&tar->ios, eh.path,
+ if (!eh.path || st.st_size > PATH_MAX ||
+ st.st_size != erofs_iostream_bread(&tar->ios, eh.path,
st.st_size))
goto invalid_tar;
eh.path[st.st_size] = '\0';
@@ -894,8 +895,9 @@ out_eot:
case 'K':
free(eh.link);
eh.link = malloc(st.st_size + 1);
- if (st.st_size > PATH_MAX || st.st_size !=
- erofs_iostream_bread(&tar->ios, eh.link, st.st_size))
+ if (!eh.link || st.st_size > PATH_MAX ||
+ st.st_size != erofs_iostream_bread(&tar->ios, eh.link,
+ st.st_size))
goto invalid_tar;
eh.link[st.st_size] = '\0';
goto restart;
--
2.43.0
prev parent reply other threads:[~2026-04-14 14:13 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-14 14:13 [PATCH erofs-utils 0/2] tar: fix parsing issues for pax and GNU extensions Zhan Xusheng
2026-04-14 14:13 ` [PATCH 1/2] erofs-utils: tar: fix out-of-bounds access when trimming pax path Zhan Xusheng
2026-04-14 14:19 ` Gao Xiang
2026-04-14 14:46 ` [PATCH erofs-utils 0/2] tar: fix parsing issues for pax and GNU extensions Zhan Xusheng
2026-04-14 14:49 ` Gao Xiang
2026-04-14 14:55 ` Zhan Xusheng
2026-04-14 14:13 ` Zhan Xusheng [this message]
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=20260414141313.46575-3-zhanxusheng@xiaomi.com \
--to=zhanxusheng1024@gmail.com \
--cc=hsiangkao@linux.alibaba.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=zhanxusheng@xiaomi.com \
/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