[PATCH] erofs-utils: tar: bound-check PAX header parsing
Vansh Choudhary
ch at vnsh.in
Wed Mar 25 03:16:08 AEDT 2026
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 at 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
More information about the Linux-erofs
mailing list