Skip to content

Commit 853bf65

Browse files
Fix ar archive entries having no type (libarchive#2290)
Also removes some whitespace damage. Closes libarchive#2241
1 parent 6e43e20 commit 853bf65

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ libarchive_test_SOURCES= \
371371
libarchive/test/test_acl_platform_posix1e.c \
372372
libarchive/test/test_acl_posix1e.c \
373373
libarchive/test/test_acl_text.c \
374+
libarchive/test/test_ar_mode.c \
374375
libarchive/test/test_archive_api_feature.c \
375376
libarchive/test/test_archive_clear_error.c \
376377
libarchive/test/test_archive_cmdline.c \

libarchive/archive_read_support_format_ar.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,9 @@ archive_read_format_ar_read_header(struct archive_read *a,
439439
if ((header_data = __archive_read_ahead(a, 60, NULL)) == NULL)
440440
/* Broken header. */
441441
return (ARCHIVE_EOF);
442-
442+
443443
unconsumed = 60;
444-
444+
445445
ret = _ar_read_header(a, entry, ar, (const char *)header_data, &unconsumed);
446446

447447
if (unconsumed)
@@ -458,7 +458,6 @@ ar_parse_common_header(struct ar *ar, struct archive_entry *entry,
458458
uint64_t n;
459459

460460
/* Copy remaining header */
461-
archive_entry_set_filetype(entry, AE_IFREG);
462461
archive_entry_set_mtime(entry,
463462
(time_t)ar_atol10(h + AR_date_offset, AR_date_size), 0L);
464463
archive_entry_set_uid(entry,
@@ -467,6 +466,7 @@ ar_parse_common_header(struct ar *ar, struct archive_entry *entry,
467466
(gid_t)ar_atol10(h + AR_gid_offset, AR_gid_size));
468467
archive_entry_set_mode(entry,
469468
(mode_t)ar_atol8(h + AR_mode_offset, AR_mode_size));
469+
archive_entry_set_filetype(entry, AE_IFREG);
470470
n = ar_atol10(h + AR_size_offset, AR_size_size);
471471

472472
ar->entry_offset = 0;

libarchive/test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ IF(ENABLE_TEST)
1515
test_acl_platform_posix1e.c
1616
test_acl_posix1e.c
1717
test_acl_text.c
18+
test_ar_mode.c
1819
test_archive_api_feature.c
1920
test_archive_clear_error.c
2021
test_archive_cmdline.c

libarchive/test/test_ar_mode.c

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*-SPDX-License-Identifier: BSD-2-Clause
2+
* Copyright (C) 2024 by наб <[email protected]>
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
*
13+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
14+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15+
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16+
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
17+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22+
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23+
*/
24+
#include "test.h"
25+
26+
static const char data[] = "!<arch>\narchivemount.1/ 0 0 0 644 0 `\n";
27+
28+
29+
DEFINE_TEST(test_ar_mode)
30+
{
31+
struct archive * ar = archive_read_new();
32+
assertEqualInt(archive_read_support_format_all(ar), ARCHIVE_OK);
33+
assertEqualInt(archive_read_open_memory(ar, data, sizeof(data) - 1), ARCHIVE_OK);
34+
35+
struct archive_entry * entry;
36+
assertEqualIntA(ar, archive_read_next_header(ar, &entry), ARCHIVE_OK);
37+
assertEqualIntA(ar, archive_entry_mode(entry), S_IFREG | 0644);
38+
39+
archive_read_free(ar);
40+
}

0 commit comments

Comments
 (0)