From: Vansh Choudhary <ch@vnsh.in>
To: linux-erofs@lists.ozlabs.org
Cc: Vansh Choudhary <ch@vnsh.in>
Subject: [PATCH] erofs-utils: tar: bound-check PAX header parsing
Date: Tue, 24 Mar 2026 16:16:08 +0000 [thread overview]
Message-ID: <20260324161608.36697-1-ch@vnsh.in> (raw)
NUL-terminate PAX header buffers before parsing them with sscanf().
Also reject PAX header lengths larger than UINT_MAX.
Fixes: 95d315fd7958 ("erofs-utils: introduce tarerofs")
Signed-off-by: Vansh Choudhary <ch@vnsh.in>
---
lib/tar.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/lib/tar.c b/lib/tar.c
index cb77f39..70bf091 100644
--- a/lib/tar.c
+++ b/lib/tar.c
@@ -471,7 +471,9 @@ int tarerofs_parse_pax_header(struct erofs_iostream *ios,
char *buf, *p;
int ret;
- buf = malloc(size);
+ if (size == UINT_MAX)
+ return -EIO;
+ buf = malloc((size_t)size + 1);
if (!buf)
return -ENOMEM;
p = buf;
@@ -479,6 +481,7 @@ int tarerofs_parse_pax_header(struct erofs_iostream *ios,
ret = erofs_iostream_bread(ios, buf, size);
if (ret != size)
goto out;
+ buf[size] = '\0';
while (p < buf + size) {
char *kv, *key, *value;
@@ -870,6 +873,8 @@ out_eot:
st.st_mode = S_IFIFO;
break;
case 'g':
+ if ((u64)st.st_size > UINT_MAX)
+ goto invalid_tar;
ret = tarerofs_parse_pax_header(&tar->ios, &tar->global,
st.st_size);
if (ret)
@@ -884,6 +889,8 @@ out_eot:
}
goto restart;
case 'x':
+ if ((u64)st.st_size > UINT_MAX)
+ goto invalid_tar;
ret = tarerofs_parse_pax_header(&tar->ios, &eh, st.st_size);
if (ret)
goto out;
--
2.43.0
reply other threads:[~2026-03-24 16:16 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260324161608.36697-1-ch@vnsh.in \
--to=ch@vnsh.in \
--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