Repository navigation
tar: When reading, open the file ourselves - #1
Closed
dag-erling wants to merge 2 commits into
Closed
dag-erling wants to merge 2 commits into
dag-erling wants to merge 2 commits into
Conversation
The library interprets a null or empty filename as “use stdio”, so just use NULL for that instead of going back and forth between NULL and "-". Observable behavior is unchanged: specifying either no filename at all, an empty filename, or "-", all result in reading from stdin or writing to stdout, as before.
Instead of passing a filename to libarchive, open the file ourselves, store the file descriptor in bsdtar->fd (which is otherwise unused in the read case), and pass that to libarchive. This very slightly speeds up opening (by bypassing unused logic in archive_read_open_filename()) and ensures that the file descriptor is available if we need it later.
| bsdtar->bytes_per_block)) | ||
| if (bsdtar->filename == NULL || *bsdtar->filename == '\0') | ||
| bsdtar->fd = STDIN_FILENO; | ||
| else if ((bsdtar->fd = open(bsdtar->filename, O_RDONLY)) < 0) |
Check failure
Code scanning / CodeQL
Uncontrolled data used in path expression High
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See individual commits for details.
While working on this, I noticed that the manual page seems to suggest that
-adefaults to bzip2. This does not appear to be the case. It defaults to no compression, just like I would expect. I'm not sure if the manual page is incorrect or if I'm just reading it wrong.I didn't have the time to add tests, but ideally we should have test cases in
bsdtar_testfor the following:stdin:-twithout-f-twith-f ''-twith-f --xwithout-f-xwith-f ''-xwith-f -stdout:-cwithout-f-cwith-f ''-cwith-f --cawithout-f-cawith-f ''-cawith-f -Some of these may already be covered, but I doubt they all are. This would be trivial to do with atf-sh; not so much with the current framework.