Skip to contentSkip to conversation

erofs-utils: tar: handle negative GNU mtime properly

PATCH New Gao Xiang 1 participant 1 message Jun 25, 2025 Library code

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/1 erofs-utils: tar: handle negative GNU mtime properly

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")
---
 lib/tar.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
lib/tar.c +4 -3
index 941fad2..72c12ed 100644
@@ -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);
Signature · 1 line
2.43.5