Bug 213255 - libarchive: tar -P cannot extract hardlinks through symlinks
Summary: libarchive: tar -P cannot extract hardlinks through symlinks
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Martin Matuska
URL:
Keywords: needs-qa, patch
Depends on:
Blocks:
 
Reported: 2016-10-06 18:31 UTC by Tijl Coosemans
Modified: 2017-07-23 21:03 UTC (History)
1 user (show)

See Also:
koobs: mfc-stable11?
koobs: mfc-stable10?
koobs: mfc-stable9?


Attachments
patch (1.71 KB, patch)
2016-11-06 19:31 UTC, Tijl Coosemans
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tijl Coosemans freebsd_committer freebsd_triage 2016-10-06 18:31:30 UTC
If you install emulators/linux_base-c6 using 'make install' files that are hardlinks to other files are not installed on the system.  An example is /compat/linux/sbin/fsck.ext2 but there are several others.  Pkg lists them all when you delete the package.  When you create a package using 'make package' and then install that package using 'pkg add' everything is fine.
Comment 1 Tijl Coosemans freebsd_committer freebsd_triage 2016-11-06 19:31:52 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.
Comment 2 Tijl Coosemans freebsd_committer freebsd_triage 2016-11-06 19:35:45 UTC
Assign to mm who works on libarchive.
Comment 3 Martin Matuska freebsd_committer freebsd_triage 2016-11-07 16:14:48 UTC
Created libarchive issue #821:
https://github.com/libarchive/libarchive/issues/821
Comment 4 commit-hook freebsd_committer freebsd_triage 2016-11-29 22:15:36 UTC
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
Comment 5 Martin Matuska freebsd_committer freebsd_triage 2016-11-29 22:21:57 UTC
Could you please verify if pkg now behaves correctly on CURRENT?
Comment 6 Tijl Coosemans freebsd_committer freebsd_triage 2016-11-30 11:05:03 UTC
(In reply to Martin Matuska from comment #5)
It works now, thanks!
Comment 7 commit-hook freebsd_committer freebsd_triage 2016-12-08 01:06:29 UTC
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
Comment 8 commit-hook freebsd_committer freebsd_triage 2016-12-08 01:07:32 UTC
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