aboutsummaryrefslogtreecommitdiffstats
path: root/libarchive/test/test_read_format_xar.c
diff options
context:
space:
mode:
Diffstat (limited to 'libarchive/test/test_read_format_xar.c')
-rw-r--r--libarchive/test/test_read_format_xar.c163
1 files changed, 162 insertions, 1 deletions
diff --git a/libarchive/test/test_read_format_xar.c b/libarchive/test/test_read_format_xar.c
index b7189eb259e6..4654f8386efb 100644
--- a/libarchive/test/test_read_format_xar.c
+++ b/libarchive/test/test_read_format_xar.c
@@ -614,6 +614,117 @@ static unsigned char archive11[] = {
0x00,0x00,0x00,0xff,0xff,0x03,0x00,0x37,0xf7,0x06,0x47
};
+/* Verify that a file which is missing timestamp information
+has the corresponding timestamps unset.
+#How to make e.g.
+ struct archive *a = archive_write_new();
+ archive_write_set_format_xar(a);
+ archive_write_add_filter_none(a);
+ size_t used, buffsize = 1500;
+ char *buff = (char*) malloc(buffsize);
+ archive_write_open_memory(a, buff, buffsize, &used);
+
+ struct archive_entry *ae = archive_entry_new();
+ archive_entry_copy_pathname(ae, "file");
+ archive_entry_set_size(ae, 8);
+ archive_write_header(a, ae);
+ archive_entry_free(ae);
+ archive_write_data(a, "12345678", 9);
+ archive_write_free(a);
+
+ std::cout << std::string(buff, used);
+ free(buff);
+
+$./a.out > f12.xar
+Verify toc has no mtime/atime sections
+$ xar --dump-toc=- -f f12.xar
+Dump contents
+$ ./a.out | od -t x1 | sed -E -e 's/^0[0-9]+//;s/^ //;s/( )([0-9a-f]{2})/0x\2,/g;$ D'
+*/
+
+static unsigned char archive12[] = {
+0x78,0x61,0x72,0x21,0x00,0x1c,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xd1,
+0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x56,0x00,0x00,0x00,0x01,0x78,0x9c,0x55,0x90,
+0x41,0x8e,0xc2,0x30,0x0c,0x45,0xf7,0x9c,0x22,0xca,0xbe,0x38,0x2d,0x2c,0x10,0x72,
+0xdb,0xdd,0x9c,0x00,0x0e,0x50,0xb5,0x6e,0x89,0x68,0x12,0xd4,0x84,0x11,0x70,0x7a,
+0x62,0x17,0x46,0x9a,0x28,0x92,0xbf,0x5f,0xec,0xef,0xc8,0xd8,0x3e,0xdc,0xac,0x7e,
+0x69,0x89,0x36,0xf8,0x5a,0x97,0x5b,0xa3,0x15,0xf9,0x3e,0x0c,0xd6,0x4f,0xb5,0x3e,
+0x9f,0x7e,0x8a,0x83,0x6e,0x9b,0x0d,0x3e,0xba,0xa5,0xd9,0x28,0x4c,0xa1,0xcf,0x41,
+0x61,0xbf,0x50,0x97,0x72,0x47,0x91,0xac,0xa3,0xa6,0x32,0xe5,0xa1,0x28,0x4d,0x61,
+0xaa,0x53,0x65,0x8e,0xf9,0xee,0x77,0x08,0xff,0x4b,0xa4,0xe9,0x42,0xfd,0x35,0xde,
+0x9d,0x8a,0xe9,0x39,0x53,0xad,0xe3,0xa5,0x2b,0x35,0xbf,0x28,0x0c,0xe3,0x18,0x29,
+0x35,0x06,0xe1,0xa3,0x84,0x46,0xfb,0x62,0x73,0x04,0x11,0x6c,0x01,0x5f,0x0f,0xc9,
+0x46,0x3b,0x93,0xb2,0x43,0xfe,0xf6,0xc7,0xc6,0x77,0x79,0x14,0x53,0x04,0x91,0x02,
+0xd3,0xf3,0xf6,0x85,0x22,0x05,0x5a,0x1f,0x06,0xe2,0x79,0xab,0x10,0xe6,0x04,0xe5,
+0x83,0xe0,0xfe,0xe0,0xdd,0x0e,0x5c,0xc6,0x41,0xf2,0x69,0xcd,0xa7,0x35,0x47,0x60,
+0x63,0xde,0x0c,0xc8,0x6a,0x10,0x64,0x51,0x6f,0x2a,0x6b,0x63,0x9a,0x01,0x79,0x57,
+0x93,0xd4,0x55,0xd4,0x06,0x1c,0x76,0x99,0x10,0x31,0x87,0x52,0x2b,0x16,0xff,0x5b,
+0x36,0x78,0x9c,0x55,0x90,0x41,0x8e,0xc2,0x30,0x0c,0x45,0xf7,0x9c,0x22,0xca,0xbe,
+0x38,0x2d,0x2c,0x10,0x72
+};
+
+static void verify12(struct archive *a, struct archive_entry *ae)
+{
+ (void)a; /* UNUSED */
+ assertEqualInt(archive_entry_mtime_is_set(ae), 0);
+ assertEqualInt(archive_entry_atime_is_set(ae), 0);
+ assertEqualInt(archive_entry_mtime(ae), 0);
+ assertEqualInt(archive_entry_atime(ae), 0);
+}
+
+
+/*
+#How to make
+echo "onetwothree" > f1
+echo "fourfivesize" > f2
+xar -cf archive13.xar f1 f2
+od -t x1 archive13.xar | sed -E -e 's/^0[0-9]+//' | sed -E -e 's/^ //' | sed -E -e 's/( )([0-9a-f]{2})/0x\2,/g;$ D'
+*/
+
+static unsigned char archive13[] = {
+0x78,0x61,0x72,0x21,0x00,0x1c,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x31,
+0x00,0x00,0x00,0x00,0x00,0x00,0x06,0xaa,0x00,0x00,0x00,0x01,0x78,0xda,0xcc,0x95,
+0xcb,0x8e,0x9b,0x30,0x14,0x86,0xf7,0x79,0x0a,0xc4,0x9e,0xe2,0x0b,0xbe,0x10,0x39,
+0xcc,0xae,0x4f,0x30,0xdd,0x74,0x67,0xec,0x43,0x82,0x86,0x4b,0x04,0x24,0xcd,0xcc,
+0xd3,0xd7,0x36,0x30,0x69,0x34,0xd3,0x51,0xda,0x4a,0xa3,0x8a,0x05,0xbf,0x8f,0x7f,
+0x9f,0xe3,0x63,0x3e,0x64,0xf5,0x70,0x69,0x9b,0xe8,0x0c,0xc3,0x58,0xf7,0xdd,0x2e,
+0xc6,0x5f,0x50,0x1c,0x41,0x67,0x7a,0x5b,0x77,0xfb,0x5d,0xfc,0xed,0xf1,0x6b,0x22,
+0xe3,0x87,0x62,0xa3,0x2e,0x7a,0x28,0x36,0x91,0x9a,0x7a,0xe3,0x5e,0x91,0x32,0x03,
+0xe8,0xc9,0xad,0x48,0xa6,0xba,0x85,0x82,0x20,0x2c,0x13,0x44,0x12,0xc2,0x1f,0x71,
+0xbe,0xc5,0x68,0x4b,0xf3,0xef,0x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0xbe,0xed,0xcc,0x2a,0x10,0x73,
+0x9e,0x84,0x13,0x2e,0x27,0xe1,0x8d,0x6f,0xf8,0x9e,0xae,0xd0,0x0a,0x8f,0x2a,0xca,
+0xf7,0x78,0xda,0xcb,0xcf,0x4b,0x2d,0x29,0xcf,0x2f,0xc9,0x28,0x4a,0x4d,0xe5,0x02,
+0x00,0x21,0x4c,0x04,0xbf,0x78,0xda,0x4b,0xcb,0x2f,0x2d,0x4a,0xcb,0x2c,0x4b,0x2d,
+0xce,0xac,0xe0,0x02,0x00,0x20,0xfa,0x04,0xc5
+};
+
enum enc {
GZIP,
BZIP2
@@ -685,6 +796,55 @@ static void verify(unsigned char *d, size_t s,
free(buff);
}
+static void verifyB(unsigned char *d, size_t s) {
+ struct archive* a;
+ struct archive_entry *entry = NULL;
+ la_int64_t buf_size;
+ unsigned char *buf;
+
+ assert((a = archive_read_new()) != NULL);
+
+ if(ARCHIVE_OK != archive_read_support_filter_gzip(a)) {
+ skipping("Unsupported gzip");
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+ return;
+ }
+
+ if(ARCHIVE_OK != archive_read_support_filter_bzip2(a)) {
+ skipping("Unsupported bzip2");
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+ return;
+ }
+
+ if(ARCHIVE_OK != archive_read_support_format_xar(a)) {
+ skipping("Unsupported xar");
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+ return;
+ }
+
+ assertA(0 == archive_read_open_memory(a, d, s));
+
+ // f1, content "onetwothree\n", size 12 bytes
+ assertA(0 == archive_read_next_header(a, &entry));
+ buf_size = archive_entry_size(entry);
+ assertA(buf_size == 12);
+ buf = (unsigned char*) malloc(buf_size);
+ assertA(NULL != buf);
+ assertA(buf_size == archive_read_data(a, buf, buf_size));
+ free(buf);
+
+ // f2, content "fourfivesix\n", size 12 bytes
+ assertA(0 == archive_read_next_header(a, &entry));
+ buf_size = archive_entry_size(entry);
+ assertA(buf_size == 12);
+ buf = (unsigned char*) malloc(buf_size);
+ assertA(NULL != buf);
+ assertA(buf_size == archive_read_data(a, buf, buf_size));
+ free(buf);
+
+ assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+}
+
DEFINE_TEST(test_read_format_xar)
{
verify(archive1, sizeof(archive1), verify0, verify1, GZIP);
@@ -698,5 +858,6 @@ DEFINE_TEST(test_read_format_xar)
verify(archive9, sizeof(archive9), verify0, NULL, GZIP);
verify(archive10, sizeof(archive10), verify0, NULL, GZIP);
verify(archive11, sizeof(archive11), verify0, NULL, GZIP);
+ verify(archive12, sizeof(archive12), verify12, NULL, GZIP);
+ verifyB(archive13, sizeof(archive13));
}
-