public inbox for linux-erofs@ozlabs.org
 help / color / mirror / Atom feed
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 1/2] erofs-utils: tar: fix out-of-bounds access when trimming pax path
Date: Tue, 14 Apr 2026 22:13:12 +0800	[thread overview]
Message-ID: <20260414141313.46575-2-zhanxusheng@xiaomi.com> (raw)
In-Reply-To: <20260414141313.46575-1-zhanxusheng@xiaomi.com>

When a PAX extended header contains a path consisting entirely of '/'
characters (e.g., "path=/"), the trailing-slash trimming loop in
tarerofs_parse_pax_header() decrements j to 0, then accesses
eh->path[-1] which is an out-of-bounds heap read.

The tar header path trimming had a similar issue fixed by commit
dcd06f421003 ("erofs-utils: mkfs: tar: fix SIGSEGV on `/` entry"),
but the PAX header path trimming was not addressed.

Add a j > 0 guard to the while condition.

Fixes: 95d315fd7958 ("erofs-utils: introduce tarerofs")
Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com>
---
 lib/tar.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/tar.c b/lib/tar.c
index eca29f5..3d92f48 100644
--- a/lib/tar.c
+++ b/lib/tar.c
@@ -509,7 +509,7 @@ int tarerofs_parse_pax_header(struct erofs_iostream *ios,
 				int j = p - 1 - value;
 				free(eh->path);
 				eh->path = strdup(value);
-				while (eh->path[j - 1] == '/')
+				while (j > 0 && eh->path[j - 1] == '/')
 					eh->path[--j] = '\0';
 			} else if (!strncmp(kv, "linkpath=",
 					sizeof("linkpath=") - 1)) {
-- 
2.43.0



  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 ` Zhan Xusheng [this message]
2026-04-14 14:19   ` [PATCH 1/2] erofs-utils: tar: fix out-of-bounds access when trimming pax path 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 ` [PATCH 2/2] erofs-utils: tar: add missing NULL checks for GNU long name/link Zhan Xusheng

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-2-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