Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid file on bsdtar command line results in internal errors... #794

Closed
kientzle opened this issue Oct 3, 2016 · 5 comments
Closed

Invalid file on bsdtar command line results in internal errors... #794

kientzle opened this issue Oct 3, 2016 · 5 comments

Comments

@kientzle
Copy link
Contributor

kientzle commented Oct 3, 2016

This was reported to the FreeBSD bugzilla as:

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=213092

# 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!
@mmatuska
Copy link
Member

mmatuska commented Oct 3, 2016

I can confirm this behavior. Simply use:
tar cf new.tar notexisting1 notexisting2

I will look into it later.

@mmatuska
Copy link
Member

mmatuska commented Oct 4, 2016

I don't understand why this was unnoticed and not catched by any test.

@ghost
Copy link

ghost commented Oct 4, 2016

Thank you!

How hard would it be write a test case for this? Have you done that in a follow up commit?

@mmatuska
Copy link
Member

mmatuska commented Oct 5, 2016

Hi, I didn't do that yet. This will probably require changing the test framework (adding new functions). The only thing we can do is look for "INTERNAL ERROR" in the stderr output. I think we should go a different way and introduce additional exit codes for tar.

@kientzle
Copy link
Contributor Author

kientzle commented Oct 7, 2016

Adding exit codes for tar is tricky: I could support having a special exit code for "INTERNAL ERROR" except that libarchive doesn't return anything special for "INTERNAL ERROR" (other than ARCHIVE_FATAL). And adding new error codes to libarchive is very hard at this point. (A significant but probably worthwhile project would add a more detailed error code to libarchive so that callers can get precise machine-readable error info.)

However, it's pretty clear that tar should never, ever print "INTERNAL ERROR", so it might be worth adding a test function that takes a file name (presumably of captured stderr) and fails if that string appears anywhere in the file. Something like:

static void
assertCleanStderr(const char *pathname) {
   ... read file, check for 'INTERNAL ERROR' (and anything else that should never appear in stderr) ...
}

Then we could start augmenting various tests with calls to assertCleanStderr(errOut) to look for recurrence of this issue in other places.

mmatuska added a commit to mmatuska/libarchive that referenced this issue Oct 11, 2016
mmatuska added a commit to mmatuska/libarchive that referenced this issue Oct 11, 2016
mmatuska added a commit that referenced this issue Oct 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants