Skip to content

Commit e3c0c8d

Browse files
authored
xar: guard against file entries containing multiple name elements (libarchive#2236)
It appears that there are xar archives (in the form of Apple .pkg files) that contain TOCs with duplicated name elements: ```xml <file id="25"> <data> ... </data> <type>file</type> <name>PackageInfo</name> <name>PackageInfo</name> <name>PackageInfo</name> </file> ``` When libarchive encounters one such file, it will produce an archive_entry named PackageInfoPackageInfoPackageInfo. To produce a test archive, the XAR writer was modified to emit two name elements.
1 parent 6ee1eeb commit e3c0c8d

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,7 @@ libarchive_test_EXTRA_DIST=\
937937
libarchive/test/test_read_format_ustar_filename_koi8r.tar.Z.uu \
938938
libarchive/test/test_read_format_warc.warc.uu \
939939
libarchive/test/test_read_format_xar_doublelink.xar.uu \
940+
libarchive/test/test_read_format_xar_duplicate_filename_node.xar.uu \
940941
libarchive/test/test_read_format_zip.zip.uu \
941942
libarchive/test/test_read_format_zip_7075_utf8_paths.zip.uu \
942943
libarchive/test/test_read_format_zip_7z_deflate.zip.uu \

libarchive/archive_read_support_format_xar.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2707,6 +2707,9 @@ xml_data(void *userData, const char *s, size_t len)
27072707

27082708
switch (xar->xmlsts) {
27092709
case FILE_NAME:
2710+
if (xar->file->has & HAS_PATHNAME)
2711+
break;
2712+
27102713
if (xar->file->parent != NULL) {
27112714
archive_string_concat(&(xar->file->pathname),
27122715
&(xar->file->parent->pathname));

libarchive/test/test_read_format_xar.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,3 +860,34 @@ DEFINE_TEST(test_read_format_xar)
860860
verify(archive12, sizeof(archive12), verify12, NULL, GZIP);
861861
verifyB(archive13, sizeof(archive13));
862862
}
863+
864+
DEFINE_TEST(test_read_format_xar_duplicate_filename_node)
865+
{
866+
static const char *reffiles[] =
867+
{
868+
"test_read_format_xar_duplicate_filename_node.xar",
869+
NULL
870+
};
871+
struct archive_entry *ae;
872+
struct archive *a;
873+
int r;
874+
875+
extract_reference_files(reffiles);
876+
assert((a = archive_read_new()) != NULL);
877+
assertA(0 == archive_read_support_filter_all(a));
878+
879+
r = archive_read_support_format_xar(a);
880+
if (r == ARCHIVE_WARN) {
881+
skipping("xar reading not fully supported on this platform");
882+
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
883+
return;
884+
}
885+
886+
assertA(0 == archive_read_open_filenames(a, reffiles, 10240));
887+
888+
assertA(0 == archive_read_next_header(a, &ae));
889+
assertEqualString("File", archive_entry_pathname(ae));
890+
891+
assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
892+
assertEqualInt(ARCHIVE_OK, archive_read_free(a));
893+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
begin 644 test_read_format_xar_duplicate_filename_node.xar
2+
M>&%R(0`<``$````````!EP````````.]`````7B<A5-);H,P%-U7ZAT0>VIC
3+
MC('((;N<H-UT][$-L<H0@1,E.7T-`0H=TI6?__OSP'>7JG3.JNUT4V]=_P6[
4+
MCJI%(W5=;-VWU[T7N[OT^8E?H+6/XW#3B`%8*%H%QMIY1E<J)9A0#S//IZ\$
5+
M;PC=^(RCM<ID=U#BHSM53F>NI=JZW0%\=R0MW>1YITR*.1K1S'3ZUL?A:`"C
6+
M-S2YFP2Y+I6CI:UFX;0&&W]O&8X&^#]AKD>5Y@,QP)G0=2-M&E'"DIBC^V\F
7+
MI3IKH>HF]0-&68!]PM$LF[6JW@8S9CM4K<Q/6O:%]\\L*^ZR8BD3O[<<)^^V
8+
M'XM>][$>J%9K57B@"FM5"0;FG_V7JB[,(?5MHB-<D.,<R<^1SD-=S7203VLX
9+
M;0D<CZ46PS:ABU?<]-%UT-(`6G'09R6]W_<KIG$LJ9\%"6!)"&80R#`)<"!R
10+
M'(DL)T`CH2384K\[6J5U,2T(\V>8#&+(0L`DQED2!@!)1(,PS^.$,I&)+"-1
11+
M&`*)./KIZ:N]:-%?COHMO%\?NI\?1_T]?@(L`P/8\;44V2:R;"\D48GC?CRL
12+
C(UAG)C5XG./E`@``)@`8>)R%4TEN@S`4W5?J'1![:F.,@<@`
13+
`
14+
end

0 commit comments

Comments
 (0)