]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
PAX writer: fix entry uname or gname longer than 32 characters
authorMartin Matuska <martin@matuska.org>
Sat, 25 Jan 2020 23:35:50 +0000 (00:35 +0100)
committerMartin Matuska <martin@matuska.org>
Sat, 25 Jan 2020 23:35:50 +0000 (00:35 +0100)
Fixes #1319

libarchive/archive_write_set_format_ustar.c
libarchive/test/test_write_format_pax.c

index e1fe974a12eeead3a9996ed0b4527a5ca0a19956..d1a06bc4f7ec1cae04e6ad0c0611f6eb6b929889 100644 (file)
@@ -513,9 +513,11 @@ __archive_write_format_header_ustar(struct archive_write *a, char h[512],
        }
        if (copy_length > 0) {
                if (copy_length > USTAR_uname_size) {
-                       archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
-                           "Username too long");
-                       ret = ARCHIVE_FAILED;
+                       if (tartype != 'x') {
+                               archive_set_error(&a->archive,
+                                   ARCHIVE_ERRNO_MISC, "Username too long");
+                               ret = ARCHIVE_FAILED;
+                       }
                        copy_length = USTAR_uname_size;
                }
                memcpy(h + USTAR_uname_offset, p, copy_length);
@@ -536,9 +538,11 @@ __archive_write_format_header_ustar(struct archive_write *a, char h[512],
        }
        if (copy_length > 0) {
                if (strlen(p) > USTAR_gname_size) {
-                       archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
-                           "Group name too long");
-                       ret = ARCHIVE_FAILED;
+                       if (tartype != 'x') {
+                               archive_set_error(&a->archive,
+                                   ARCHIVE_ERRNO_MISC, "Group name too long");
+                               ret = ARCHIVE_FAILED;
+                       }
                        copy_length = USTAR_gname_size;
                }
                memcpy(h + USTAR_gname_offset, p, copy_length);
index 41a423a96a0e75308a363587a9cca173fec2c4ff..4538aac8241d94cd39ea3b446d33a50009d683dc 100644 (file)
@@ -104,6 +104,28 @@ DEFINE_TEST(test_write_format_pax)
                assertEqualIntA(a, 1024, archive_write_data(a, nulls, 1024));
        assertEqualIntA(a, 8, archive_write_data(a, "12345678", 9));
 
+       /*
+        * "file4" is similar to "file1" but has a large uid, large gid,
+        * uname and gname are longer than 32 characters
+        */
+       assert((ae = archive_entry_new()) != NULL);
+       archive_entry_set_atime(ae, 2, 20);
+       archive_entry_set_birthtime(ae, 3, 30);
+       archive_entry_set_ctime(ae, 4, 40);
+       archive_entry_set_mtime(ae, 5, 50);
+       archive_entry_copy_pathname(ae, "file4");
+       archive_entry_set_mode(ae, S_IFREG | 0755);
+       archive_entry_set_size(ae, 8);
+       archive_entry_copy_uname(ae,
+           "long-uname123456789012345678901234567890");
+       archive_entry_copy_gname(ae,
+           "long-gname123456789012345678901234567890");
+       archive_entry_set_uid(ae, 536870912);
+       archive_entry_set_gid(ae, 536870913);
+       assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
+       archive_entry_free(ae);
+       assertEqualIntA(a, 8, archive_write_data(a, "12345678", 9));
+
        /*
         * XXX TODO XXX Archive directory, other file types.
         * Archive extended attributes, ACLs, other metadata.
@@ -198,6 +220,30 @@ DEFINE_TEST(test_write_format_pax)
        assertEqualIntA(a, 8, archive_read_data(a, buff2, 10));
        assertEqualMem(buff2, "12345678", 8);
 
+       /*
+        * Read "file4
+        */
+       assertEqualIntA(a, 0, archive_read_next_header(a, &ae));
+       assertEqualInt(2, archive_entry_atime(ae));
+       assertEqualInt(20, archive_entry_atime_nsec(ae));
+       assertEqualInt(3, archive_entry_birthtime(ae));
+       assertEqualInt(30, archive_entry_birthtime_nsec(ae));
+       assertEqualInt(4, archive_entry_ctime(ae));
+       assertEqualInt(40, archive_entry_ctime_nsec(ae));
+       assertEqualInt(5, archive_entry_mtime(ae));
+       assertEqualInt(50, archive_entry_mtime_nsec(ae));
+       assertEqualString("file4", archive_entry_pathname(ae));
+       assertEqualString("long-uname123456789012345678901234567890",
+           archive_entry_uname(ae));
+       assertEqualString("long-gname123456789012345678901234567890",
+           archive_entry_gname(ae));
+       assertEqualInt(536870912, archive_entry_uid(ae));
+       assertEqualInt(536870913, archive_entry_gid(ae));
+       assert((S_IFREG | 0755) == archive_entry_mode(ae));
+       assertEqualInt(8, archive_entry_size(ae));
+       assertEqualIntA(a, 8, archive_read_data(a, buff2, 10));
+       assertEqualMem(buff2, "12345678", 8);
+
        /*
         * Verify the end of the archive.
         */