Summary: | libarchive: tar -P cannot extract hardlinks through symlinks | ||||||
---|---|---|---|---|---|---|---|
Product: | Base System | Reporter: | Tijl Coosemans <tijl> | ||||
Component: | bin | Assignee: | Martin Matuska <mm> | ||||
Status: | Closed FIXED | ||||||
Severity: | Affects Only Me | CC: | pi | ||||
Priority: | --- | Keywords: | needs-qa, patch | ||||
Version: | CURRENT | Flags: | koobs:
mfc-stable11?
koobs: mfc-stable10? koobs: mfc-stable9? |
||||
Hardware: | Any | ||||||
OS: | Any | ||||||
Attachments: |
|
Description
Tijl Coosemans
2016-10-06 18:31:30 UTC
Created attachment 176698 [details]
patch
So this turned out to be caused by /compat being a symlink to usr/compat on my system and it's a bug in libarchive. It can be reproduced with tar like this:
% mkdir dir2
% ln -s dir2 dir
% touch dir/file
% ln dir/file dir/file2
% tar cf dir.tar dir/file dir/file2
% rm dir/*
% tar xf dir.tar -P
dir/file2: Can't create 'dir/file2'
tar: Error exit delayed from previous errors.
tijl@kalimero:~/tmp/test% ls -l dir/
total 0
-rw-r--r-- 1 tijl wheel 0 6 Nov 20:05 file
With -P extraction through a symlink (dir->dir2) should work, but fails for hardlinks.
The attached patch fixes this. In archive_write_disk_posix.c the function create_filesystem_object() calls check_symlinks_fsobj() in the case of hardlinks, but not in the case of symlinks or regular files. The patch removes this call. check_symlinks_fsobj() is still called elsewhere in the same file and the 'tar xf' command above without -P still fails on both archive entries.
Assign to mm who works on libarchive. Created libarchive issue #821: https://github.com/libarchive/libarchive/issues/821 A commit references this bug: Author: mm Date: Tue Nov 29 22:14:43 UTC 2016 New revision: 309300 URL: https://svnweb.freebsd.org/changeset/base/309300 Log: MFV r309299: Sync libarchive with vendor. Important vendor bugfixes (relevant to FreeBSD): #821: tar -P cannot extract hardlinks through symlinks #825: Add sanity check of tar "uid, "gid" and "mtime" fields PR: 213255 Reported by: Tijl Coosemans <tilj@FreeBSD.org> MFC after: 1 week Changes: _U head/contrib/libarchive/ head/contrib/libarchive/NEWS head/contrib/libarchive/libarchive/archive_acl.c head/contrib/libarchive/libarchive/archive_entry.c head/contrib/libarchive/libarchive/archive_entry.h head/contrib/libarchive/libarchive/archive_entry_acl.3 head/contrib/libarchive/libarchive/archive_read_disk_entry_from_file.c head/contrib/libarchive/libarchive/archive_read_support_filter_xz.c head/contrib/libarchive/libarchive/archive_read_support_format_tar.c head/contrib/libarchive/libarchive/archive_read_support_format_xar.c head/contrib/libarchive/libarchive/archive_write_disk_posix.c head/contrib/libarchive/libarchive/test/test_compat_gtar.c head/contrib/libarchive/libarchive/test/test_compat_gtar_2.tar.uu head/contrib/libarchive/libarchive/test/test_compat_star_acl_posix1e.c head/contrib/libarchive/libarchive/test/test_compat_star_acl_posix1e.tar.uu head/contrib/libarchive/libarchive/test/test_read_format_raw.bufr.uu head/contrib/libarchive/libarchive/test/test_read_format_raw.c head/contrib/libarchive/libarchive/test/test_sparse_basic.c head/contrib/libarchive/tar/test/test_symlink_dir.c head/lib/libarchive/tests/Makefile Could you please verify if pkg now behaves correctly on CURRENT? (In reply to Martin Matuska from comment #5) It works now, thanks! A commit references this bug: Author: mm Date: Thu Dec 8 01:06:09 UTC 2016 New revision: 309701 URL: https://svnweb.freebsd.org/changeset/base/309701 Log: Partial MFC r309300: Apply fix for libarchive issue #821: "tar -P" cannot extract hardlinks through symlinks PR: 213255 Reported by: Tijl Coosemans <tilj@FreeBSD.org> Changes: stable/11/contrib/libarchive/libarchive/archive_write_disk_posix.c stable/11/contrib/libarchive/tar/test/test_symlink_dir.c A commit references this bug: Author: mm Date: Thu Dec 8 01:07:00 UTC 2016 New revision: 309702 URL: https://svnweb.freebsd.org/changeset/base/309702 Log: Partial MFC r309300: Apply fix for libarchive issue #821: "tar -P" cannot extract hardlinks through symlinks PR: 213255 Reported by: Tijl Coosemans <tilj@FreeBSD.org> Changes: stable/10/contrib/libarchive/libarchive/archive_write_disk_posix.c stable/10/contrib/libarchive/tar/test/test_symlink_dir.c |