From: Utkal Singh <singhutkal015@gmail.com>
To: linux-erofs@lists.ozlabs.org
Cc: xiang@kernel.org, yifan.yfzhao@foxmail.com,
Utkal Singh <singhutkal015@gmail.com>
Subject: [PATCH v2 2/2] erofs-utils: lib/tar: reject negative size= value in PAX header
Date: Mon, 16 Mar 2026 06:51:19 +0000 [thread overview]
Message-ID: <20260316065119.21726-3-singhutkal015@gmail.com> (raw)
In-Reply-To: <20260316065119.21726-1-singhutkal015@gmail.com>
The PAX extended header size= field is parsed into a signed long
long but no check is made for negative values before assigning to
eh->st.st_size. A crafted PAX header with size=-1 passes the
existing format check, resulting in a negative file size that can
cause incorrect memory allocation and heap corruption in subsequent
read or seek operations.
Add an explicit check to reject negative size= values with -EINVAL.
Signed-off-by: Utkal Singh <singhutkal015@gmail.com>
---
lib/tar.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/lib/tar.c b/lib/tar.c
index be86984..6fa2cda 100644
--- a/lib/tar.c
+++ b/lib/tar.c
@@ -546,6 +546,11 @@ int tarerofs_parse_pax_header(struct erofs_iostream *ios,
ret = -EIO;
goto out;
}
+ if (lln < 0) {
+ erofs_err("invalid negative size= in PAX header");
+ ret = -EINVAL;
+ goto out;
+ }
eh->st.st_size = lln;
eh->use_size = true;
} else if (!strncmp(kv, "uid=", sizeof("uid=") - 1)) {
--
2.43.0
next prev parent reply other threads:[~2026-03-16 6:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-16 6:51 [PATCH v2 0/2] erofs-utils: lib/tar: fix PAX header parsing issues Utkal Singh
2026-03-16 6:51 ` [PATCH v2 1/2] erofs-utils: lib/tar: skip PAX entries with empty path Utkal Singh
2026-03-16 6:51 ` Utkal Singh [this message]
2026-03-16 7:35 ` [PATCH v2 0/2] erofs-utils: lib/tar: fix PAX header parsing issues Gao Xiang
2026-03-16 7:48 ` Utkal Singh
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=20260316065119.21726-3-singhutkal015@gmail.com \
--to=singhutkal015@gmail.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=xiang@kernel.org \
--cc=yifan.yfzhao@foxmail.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