Bug 213092 - tar(1) continues to run and error after non-existent file
Summary: tar(1) continues to run and error after non-existent file
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: amd64 Any
: --- Affects Only Me
Assignee: Martin Matuska
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-29 16:05 UTC by sega01
Modified: 2017-10-24 09:51 UTC (History)
3 users (show)

See Also:
koobs: mfc-stable11+
koobs: mfc-stable10+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description sega01 2016-09-29 16:05:35 UTC
I suspect this fix is what caused the behavior: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=205358

Prior, I was using the broken functionality as a feature:

tar -cf - file file file-may-be-here file file, and it was fine up till 10.3.

Now in 11.0-RELEASE, it breaks. But it's ugly.

# ls
foo     that    this
# tar cvf - 404 > /dev/null
tar: 404: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors.
# echo $?
1

That's all fine and dandy. I think it could be reasonable behavior. What I don't like is this.

# tar cvf - foo that this 404 that this 404 that this > /dev/null
a foo
a foo/bar
a that
a this
tar: 404: Cannot stat: No such file or directory
tar: INTERNAL ERROR: Function 'archive_read_disk_open' invoked with archive structure in state 'header', should be in state 'new/closed': Unknown error: -1
tar: INTERNAL ERROR: Function 'archive_read_disk_open' invoked with archive structure in state 'header', should be in state 'new/closed': Unknown error: -1
tar: INTERNAL ERROR: Function 'archive_read_disk_open' invoked with archive structure in state 'header', should be in state 'new/closed': Unknown error: -1
tar: INTERNAL ERROR: Function 'archive_read_disk_open' invoked with archive structure in state 'header', should be in state 'new/closed': Unknown error: -1
tar: INTERNAL ERROR: Function 'archive_read_disk_open' invoked with archive structure in state 'header', should be in state 'new/closed': Unknown error: -1
tar: Error exit delayed from previous errors.
# echo $?
1

It at least returns 1, but it doesn't stop execution. It seems to get into a pretty yucky state. I think maybe tar isn't handling the return from libarchive properly? I think tar should quit immediately on a failure like this, rather than spinning its wheels in a weird state.

In order to see the libarchive error, you have to give tar at least one more file argument after a file that doesn't exist.

Thank you!
Comment 1 kientzle 2016-10-03 00:35:06 UTC
I've copied your report to the libarchive bug tracker as:

   https://github.com/libarchive/libarchive/issues/794
Comment 2 commit-hook freebsd_committer freebsd_triage 2016-10-04 11:44:56 UTC
A commit references this bug:

Author: mm
Date: Tue Oct  4 11:44:24 UTC 2016
New revision: 306669
URL: https://svnweb.freebsd.org/changeset/base/306669

Log:
  Update vendor/libarchive to git 024be27d1b299c030e8841bed3002ee07ba9eedc

  Important vendor bugfixes (relevant to FreeBSD):
  #747: Out of bounds read in mtree parser
  #761: heap-based buffer overflow in read_Header (7-zip)
  #784: Invalid file on bsdtar command line results in internal errors (1)

  PR:		213092 (1)
  Obtained from:	https://github.com/libarchive/libarchive

Changes:
  vendor/libarchive/dist/Makefile.am
  vendor/libarchive/dist/cat/test/main.c
  vendor/libarchive/dist/cat/test/test.h
  vendor/libarchive/dist/cpio/test/main.c
  vendor/libarchive/dist/cpio/test/test.h
  vendor/libarchive/dist/examples/minitar/minitar.c
  vendor/libarchive/dist/libarchive/archive_read_support_format_7zip.c
  vendor/libarchive/dist/libarchive/archive_read_support_format_mtree.c
  vendor/libarchive/dist/libarchive/test/CMakeLists.txt
  vendor/libarchive/dist/libarchive/test/main.c
  vendor/libarchive/dist/libarchive/test/test_acl_freebsd_nfs4.c
  vendor/libarchive/dist/libarchive/test/test_read_format_mtree_crash747.c
  vendor/libarchive/dist/libarchive/test/test_read_format_mtree_crash747.mtree.bz2.uu
  vendor/libarchive/dist/libarchive/test/test_read_set_format.c
  vendor/libarchive/dist/tar/subst.c
  vendor/libarchive/dist/tar/test/main.c
  vendor/libarchive/dist/tar/test/test.h
  vendor/libarchive/dist/tar/test/test_option_H_upper.c
  vendor/libarchive/dist/tar/test/test_option_L_upper.c
  vendor/libarchive/dist/tar/test/test_option_U_upper.c
  vendor/libarchive/dist/tar/test/test_option_n.c
  vendor/libarchive/dist/tar/write.c
Comment 3 commit-hook freebsd_committer freebsd_triage 2016-10-04 11:57:00 UTC
A commit references this bug:

Author: mm
Date: Tue Oct  4 11:56:49 UTC 2016
New revision: 306670
URL: https://svnweb.freebsd.org/changeset/base/306670

Log:
  MFV r306669:
  Sync libarchive with vendor including security fixes.

  Important vendor bugfixes (relevant to FreeBSD):
  #747: Out of bounds read in mtree parser
  #761: heap-based buffer overflow in read_Header (7-zip)
  #784: Invalid file on bsdtar command line results in internal errors (1)

  PR:		213092 (1)
  MFC after:	1 week

Changes:
_U  head/contrib/libarchive/
  head/contrib/libarchive/cat/test/main.c
  head/contrib/libarchive/cat/test/test.h
  head/contrib/libarchive/cpio/test/main.c
  head/contrib/libarchive/cpio/test/test.h
  head/contrib/libarchive/libarchive/archive_read_support_format_7zip.c
  head/contrib/libarchive/libarchive/archive_read_support_format_mtree.c
  head/contrib/libarchive/libarchive/test/main.c
  head/contrib/libarchive/libarchive/test/test_acl_freebsd_nfs4.c
  head/contrib/libarchive/libarchive/test/test_read_format_mtree_crash747.c
  head/contrib/libarchive/libarchive/test/test_read_format_mtree_crash747.mtree.bz2.uu
  head/contrib/libarchive/libarchive/test/test_read_set_format.c
  head/contrib/libarchive/tar/subst.c
  head/contrib/libarchive/tar/test/main.c
  head/contrib/libarchive/tar/test/test.h
  head/contrib/libarchive/tar/test/test_option_H_upper.c
  head/contrib/libarchive/tar/test/test_option_L_upper.c
  head/contrib/libarchive/tar/test/test_option_U_upper.c
  head/contrib/libarchive/tar/test/test_option_n.c
  head/contrib/libarchive/tar/write.c
  head/lib/libarchive/tests/Makefile
Comment 4 commit-hook freebsd_committer freebsd_triage 2016-10-12 10:28:58 UTC
A commit references this bug:

Author: mm
Date: Wed Oct 12 10:28:24 UTC 2016
New revision: 307138
URL: https://svnweb.freebsd.org/changeset/base/307138

Log:
  MFC r306670:
  Sync libarchive with vendor including security fixes.

  Important vendor bugfixes (relevant to FreeBSD):
  #747: Out of bounds read in mtree parser
  #761: heap-based buffer overflow in read_Header (7-zip)
  #794: Invalid file on bsdtar command line results in internal errors (1)

  PR:	213092 (1)

Changes:
_U  stable/11/
  stable/11/contrib/libarchive/cat/test/main.c
  stable/11/contrib/libarchive/cat/test/test.h
  stable/11/contrib/libarchive/cpio/test/main.c
  stable/11/contrib/libarchive/cpio/test/test.h
  stable/11/contrib/libarchive/libarchive/archive_read_support_format_7zip.c
  stable/11/contrib/libarchive/libarchive/archive_read_support_format_mtree.c
  stable/11/contrib/libarchive/libarchive/test/main.c
  stable/11/contrib/libarchive/libarchive/test/test_acl_freebsd_nfs4.c
  stable/11/contrib/libarchive/libarchive/test/test_read_format_mtree_crash747.c
  stable/11/contrib/libarchive/libarchive/test/test_read_format_mtree_crash747.mtree.bz2.uu
  stable/11/contrib/libarchive/libarchive/test/test_read_set_format.c
  stable/11/contrib/libarchive/tar/subst.c
  stable/11/contrib/libarchive/tar/test/main.c
  stable/11/contrib/libarchive/tar/test/test.h
  stable/11/contrib/libarchive/tar/test/test_option_H_upper.c
  stable/11/contrib/libarchive/tar/test/test_option_L_upper.c
  stable/11/contrib/libarchive/tar/test/test_option_U_upper.c
  stable/11/contrib/libarchive/tar/test/test_option_n.c
  stable/11/contrib/libarchive/tar/write.c
  stable/11/lib/libarchive/tests/Makefile
Comment 5 commit-hook freebsd_committer freebsd_triage 2016-10-12 10:30:01 UTC
A commit references this bug:

Author: mm
Date: Wed Oct 12 10:28:57 UTC 2016
New revision: 307139
URL: https://svnweb.freebsd.org/changeset/base/307139

Log:
  MFC r306670:
  Sync libarchive with vendor including security fixes.

  Important vendor bugfixes (relevant to FreeBSD):
  #747: Out of bounds read in mtree parser
  #761: heap-based buffer overflow in read_Header (7-zip)
  #794: Invalid file on bsdtar command line results in internal errors (1)

  PR:	213092 (1)

Changes:
_U  stable/10/
  stable/10/contrib/libarchive/cat/test/main.c
  stable/10/contrib/libarchive/cat/test/test.h
  stable/10/contrib/libarchive/cpio/test/main.c
  stable/10/contrib/libarchive/cpio/test/test.h
  stable/10/contrib/libarchive/libarchive/archive_read_support_format_7zip.c
  stable/10/contrib/libarchive/libarchive/archive_read_support_format_mtree.c
  stable/10/contrib/libarchive/libarchive/test/main.c
  stable/10/contrib/libarchive/libarchive/test/test_acl_freebsd_nfs4.c
  stable/10/contrib/libarchive/libarchive/test/test_read_format_mtree_crash747.c
  stable/10/contrib/libarchive/libarchive/test/test_read_format_mtree_crash747.mtree.bz2.uu
  stable/10/contrib/libarchive/libarchive/test/test_read_set_format.c
  stable/10/contrib/libarchive/tar/subst.c
  stable/10/contrib/libarchive/tar/test/main.c
  stable/10/contrib/libarchive/tar/test/test.h
  stable/10/contrib/libarchive/tar/test/test_option_H_upper.c
  stable/10/contrib/libarchive/tar/test/test_option_L_upper.c
  stable/10/contrib/libarchive/tar/test/test_option_U_upper.c
  stable/10/contrib/libarchive/tar/test/test_option_n.c
  stable/10/contrib/libarchive/tar/write.c
  stable/10/lib/libarchive/tests/Makefile