[PATCH] erofs-utils: tar: handle negative GNU mtime properly

Gao Xiang hsiangkao at linux.alibaba.com
Wed Jun 25 21:45:09 AEST 2025


EROFS natively supports pre-1970 timestamps for file data archiving,
and this was already handled when building from directories.

Fixes: 95d315fd7958 ("erofs-utils: introduce tarerofs")
Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
 lib/tar.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/tar.c b/lib/tar.c
index 941fad2..72c12ed 100644
--- a/lib/tar.c
+++ b/lib/tar.c
@@ -283,7 +283,7 @@ static long long tarerofs_otoi(const char *ptr, int len)
 	inp[len] = '\0';
 
 	errno = 0;
-	val = strtol(inp, &endp, 8);
+	val = strtoll(inp, &endp, 8);
 	if ((*endp == '\0' && endp == inp) |
 	    (*endp != '\0' && *endp != ' '))
 		errno = EINVAL;
@@ -292,16 +292,17 @@ static long long tarerofs_otoi(const char *ptr, int len)
 
 static long long tarerofs_parsenum(const char *ptr, int len)
 {
+	errno = 0;
 	/*
 	 * For fields containing numbers or timestamps that are out of range
 	 * for the basic format, the GNU format uses a base-256 representation
 	 * instead of an ASCII octal number.
 	 */
-	if (*(char *)ptr == '\200') {
+	if (*(char *)ptr == '\200' || *(char *)ptr == '\377') {
 		long long res = 0;
 
 		while (--len)
-			res = (res << 8) + (u8)*(++ptr);
+			res = (res << 8) | (u8)*(++ptr);
 		return res;
 	}
 	return tarerofs_otoi(ptr, len);
-- 
2.43.5



More information about the Linux-erofs mailing list