]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
warc: test future date conversion
authordatauwu <datauwu@users.noreply.github.com>
Sat, 1 Aug 2026 18:57:01 +0000 (02:57 +0800)
committerdatauwu <datauwu@users.noreply.github.com>
Sat, 1 Aug 2026 18:57:01 +0000 (02:57 +0800)
Add a WARC date after 2038 to cover the fallback time conversion.
On 64-bit time_t, it must parse as the expected Unix timestamp.

libarchive/test/test_read_format_warc.c

index be14b88b1a29c08f90dd5b560450a4318a88759d..3b08ceee82523e212d89760d2a3665618512db0f 100644 (file)
@@ -202,3 +202,37 @@ DEFINE_TEST(test_read_format_warc_truncated_body)
        assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
        assertEqualInt(ARCHIVE_OK, archive_read_free(a));
 }
+
+DEFINE_TEST(test_read_format_warc_future_date)
+{
+       static const char warc[] =
+           "WARC/1.0\r\n"
+           "WARC-Type: resource\r\n"
+           "WARC-Date: 2039-01-01T00:00:00Z\r\n"
+           "WARC-Target-URI: file://test.txt\r\n"
+           "Content-Length: 0\r\n"
+           "\r\n"
+           "\r\n\r\n";
+       struct archive_entry *ae;
+       struct archive *a;
+
+       if (sizeof(time_t) < 8) {
+               skipping("This test requires a 64-bit time_t");
+               return;
+       }
+
+       assert((a = archive_read_new()) != NULL);
+       assertEqualIntA(a, ARCHIVE_OK,
+           archive_read_support_filter_all(a));
+       assertEqualIntA(a, ARCHIVE_OK,
+           archive_read_support_format_all(a));
+       assertEqualIntA(a, ARCHIVE_OK,
+           archive_read_open_memory(a, warc, sizeof(warc) - 1U));
+
+       assertEqualIntA(a, ARCHIVE_OK,
+           archive_read_next_header(a, &ae));
+       assertEqualInt(2177452800LL, archive_entry_mtime(ae));
+
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
+       assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+}