From 4fdfd1f62a9d50298b0bb71e8bea04174af4a3ab Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Wed, 24 Jul 2019 13:36:50 +0200 Subject: Fix processing of tar mtime on 32 bit systems struct stat uses time_t to store time values. On some 32 bit systems, this may be a 32 bit integer. This patch adds a broken-out 64 bit time value to tar_header_decoded_t and makes sure to clamp the value to +/- (2^32 - 1) if required when writing it back to a struct stat. Reported-by: Matt Turner Signed-off-by: David Oberhollenzer --- tests/tar_gnu.c | 13 ++++++++++++- tests/tar_pax.c | 12 +++++++++++- tests/tar_ustar.c | 13 ++++++++++++- tests/tar_xattr_bsd.c | 1 + tests/tar_xattr_schily.c | 1 + 5 files changed, 37 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/tar_gnu.c b/tests/tar_gnu.c index c5f8ddb..4f78da7 100644 --- a/tests/tar_gnu.c +++ b/tests/tar_gnu.c @@ -48,6 +48,7 @@ int main(void) assert(hdr.sb.st_gid == 01750); assert(hdr.sb.st_size == 5); assert(hdr.sb.st_mtime == 1542905892); + assert(hdr.mtime == 1542905892); assert(strcmp(hdr.name, "input.txt") == 0); assert(!hdr.unknown_record); assert(read_data("data0", fd, buffer, 5) == 0); @@ -63,6 +64,7 @@ int main(void) assert(hdr.sb.st_gid == 01750); assert(hdr.sb.st_size == 5); assert(hdr.sb.st_mtime == 013375560044); + assert(hdr.mtime == 013375560044); assert(strcmp(hdr.name, "input.txt") == 0); assert(!hdr.unknown_record); assert(read_data("data1", fd, buffer, 5) == 0); @@ -78,6 +80,7 @@ int main(void) assert(hdr.sb.st_gid == 01750); assert(hdr.sb.st_size == 8589934592); assert(hdr.sb.st_mtime == 013375730126); + assert(hdr.mtime == 013375730126); assert(strcmp(hdr.name, "big-file.bin") == 0); assert(!hdr.unknown_record); clear_header(&hdr); @@ -90,6 +93,7 @@ int main(void) assert(hdr.sb.st_gid == 0x80000000); assert(hdr.sb.st_size == 5); assert(hdr.sb.st_mtime == 013376036700); + assert(hdr.mtime == 013376036700); assert(strcmp(hdr.name, "input.txt") == 0); assert(!hdr.unknown_record); assert(read_data("data2", fd, buffer, 5) == 0); @@ -104,7 +108,12 @@ int main(void) assert(hdr.sb.st_uid == 01750); assert(hdr.sb.st_gid == 01750); assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 8589934592); +#if SIZEOF_TIME_T < 8 + assert(hdr.sb.st_mtime == INT32_MAX); +#else + assert(hdr.sb.st_mtime == 8589934592L); +#endif + assert(hdr.mtime == 8589934592L); assert(strcmp(hdr.name, "input.txt") == 0); assert(!hdr.unknown_record); assert(read_data("data3", fd, buffer, 5) == 0); @@ -120,6 +129,7 @@ int main(void) assert(hdr.sb.st_gid == 01750); assert(hdr.sb.st_size == 5); assert(hdr.sb.st_mtime == -315622800); + assert(hdr.mtime == -315622800); assert(strcmp(hdr.name, "input.txt") == 0); assert(!hdr.unknown_record); assert(read_data("data4", fd, buffer, 5) == 0); @@ -135,6 +145,7 @@ int main(void) assert(hdr.sb.st_gid == 01750); assert(hdr.sb.st_size == 5); assert(hdr.sb.st_mtime == 1542909670); + assert(hdr.mtime == 1542909670); assert(strcmp(hdr.name, filename) == 0); assert(!hdr.unknown_record); assert(read_data("data5", fd, buffer, 5) == 0); diff --git a/tests/tar_pax.c b/tests/tar_pax.c index c383427..9ca12ff 100644 --- a/tests/tar_pax.c +++ b/tests/tar_pax.c @@ -48,6 +48,7 @@ int main(void) assert(hdr.sb.st_gid == 01750); assert(hdr.sb.st_size == 5); assert(hdr.sb.st_mtime == 1542905892); + assert(hdr.mtime == 1542905892); assert(strcmp(hdr.name, "input.txt") == 0); assert(!hdr.unknown_record); assert(read_data("data0", fd, buffer, 5) == 0); @@ -63,6 +64,7 @@ int main(void) assert(hdr.sb.st_gid == 01750); assert(hdr.sb.st_size == 8589934592); assert(hdr.sb.st_mtime == 1542959190); + assert(hdr.mtime == 1542959190); assert(strcmp(hdr.name, "big-file.bin") == 0); assert(!hdr.unknown_record); clear_header(&hdr); @@ -75,6 +77,7 @@ int main(void) assert(hdr.sb.st_gid == 2147483648); assert(hdr.sb.st_size == 5); assert(hdr.sb.st_mtime == 013376036700); + assert(hdr.mtime == 013376036700); assert(strcmp(hdr.name, "input.txt") == 0); assert(!hdr.unknown_record); assert(read_data("data1", fd, buffer, 5) == 0); @@ -89,7 +92,12 @@ int main(void) assert(hdr.sb.st_uid == 01750); assert(hdr.sb.st_gid == 01750); assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 8589934592); +#if SIZEOF_TIME_T < 8 + assert(hdr.sb.st_mtime == INT32_MAX); +#else + assert(hdr.sb.st_mtime == 8589934592L); +#endif + assert(hdr.mtime == 8589934592L); assert(strcmp(hdr.name, "input.txt") == 0); assert(!hdr.unknown_record); assert(read_data("data2", fd, buffer, 5) == 0); @@ -105,6 +113,7 @@ int main(void) assert(hdr.sb.st_gid == 01750); assert(hdr.sb.st_size == 5); assert(hdr.sb.st_mtime == -315622800); + assert(hdr.mtime == -315622800); assert(strcmp(hdr.name, "input.txt") == 0); assert(!hdr.unknown_record); assert(read_data("data3", fd, buffer, 5) == 0); @@ -120,6 +129,7 @@ int main(void) assert(hdr.sb.st_gid == 01750); assert(hdr.sb.st_size == 5); assert(hdr.sb.st_mtime == 1542909670); + assert(hdr.mtime == 1542909670); assert(strcmp(hdr.name, filename) == 0); assert(!hdr.unknown_record); assert(read_data("data4", fd, buffer, 5) == 0); diff --git a/tests/tar_ustar.c b/tests/tar_ustar.c index d497b15..695665f 100644 --- a/tests/tar_ustar.c +++ b/tests/tar_ustar.c @@ -48,6 +48,7 @@ int main(void) assert(hdr.sb.st_gid == 01750); assert(hdr.sb.st_size == 5); assert(hdr.sb.st_mtime == 1542905892); + assert(hdr.mtime == 1542905892); assert(strcmp(hdr.name, "input.txt") == 0); assert(!hdr.unknown_record); assert(read_data("data0", fd, buffer, 5) == 0); @@ -63,6 +64,7 @@ int main(void) assert(hdr.sb.st_gid == 01750); assert(hdr.sb.st_size == 5); assert(hdr.sb.st_mtime == 1542905892); + assert(hdr.mtime == 1542905892); assert(strcmp(hdr.name, "input.txt") == 0); assert(!hdr.unknown_record); assert(read_data("data1", fd, buffer, 5) == 0); @@ -78,6 +80,7 @@ int main(void) assert(hdr.sb.st_gid == 01750); assert(hdr.sb.st_size == 5); assert(hdr.sb.st_mtime == 1542905892); + assert(hdr.mtime == 1542905892); assert(strcmp(hdr.name, "input.txt") == 0); assert(!hdr.unknown_record); assert(read_data("data2", fd, buffer, 5) == 0); @@ -93,6 +96,7 @@ int main(void) assert(hdr.sb.st_gid == 01750); assert(hdr.sb.st_size == 8589934592); assert(hdr.sb.st_mtime == 013375730126); + assert(hdr.mtime == 013375730126); assert(strcmp(hdr.name, "big-file.bin") == 0); assert(!hdr.unknown_record); clear_header(&hdr); @@ -105,6 +109,7 @@ int main(void) assert(hdr.sb.st_gid == 8388608); assert(hdr.sb.st_size == 5); assert(hdr.sb.st_mtime == 013376036700); + assert(hdr.mtime == 013376036700); assert(strcmp(hdr.name, "input.txt") == 0); assert(!hdr.unknown_record); assert(read_data("data3", fd, buffer, 5) == 0); @@ -119,7 +124,12 @@ int main(void) assert(hdr.sb.st_uid == 01750); assert(hdr.sb.st_gid == 01750); assert(hdr.sb.st_size == 5); - assert(hdr.sb.st_mtime == 8589934592); +#if SIZEOF_TIME_T < 8 + assert(hdr.sb.st_mtime == INT32_MAX); +#else + assert(hdr.sb.st_mtime == 8589934592L); +#endif + assert(hdr.mtime == 8589934592L); assert(strcmp(hdr.name, "input.txt") == 0); assert(!hdr.unknown_record); assert(read_data("data4", fd, buffer, 5) == 0); @@ -135,6 +145,7 @@ int main(void) assert(hdr.sb.st_gid == 01750); assert(hdr.sb.st_size == 5); assert(hdr.sb.st_mtime == 1542909670); + assert(hdr.mtime == 1542909670); assert(strcmp(hdr.name, filename) == 0); assert(!hdr.unknown_record); assert(read_data("data5", fd, buffer, 5) == 0); diff --git a/tests/tar_xattr_bsd.c b/tests/tar_xattr_bsd.c index 360448f..b2a1290 100644 --- a/tests/tar_xattr_bsd.c +++ b/tests/tar_xattr_bsd.c @@ -43,6 +43,7 @@ int main(void) assert(hdr.sb.st_gid == 01750); assert(hdr.sb.st_size == 5); assert(hdr.sb.st_mtime == 1543094477); + assert(hdr.mtime == 1543094477); assert(strcmp(hdr.name, "input.txt") == 0); assert(!hdr.unknown_record); assert(read_data("data0", fd, buffer, 5) == 0); diff --git a/tests/tar_xattr_schily.c b/tests/tar_xattr_schily.c index e49bdd9..9030a45 100644 --- a/tests/tar_xattr_schily.c +++ b/tests/tar_xattr_schily.c @@ -43,6 +43,7 @@ int main(void) assert(hdr.sb.st_gid == 01750); assert(hdr.sb.st_size == 5); assert(hdr.sb.st_mtime == 1543094477); + assert(hdr.mtime == 1543094477); assert(strcmp(hdr.name, "input.txt") == 0); assert(!hdr.unknown_record); assert(read_data("data0", fd, buffer, 5) == 0); -- cgit v1.2.3