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

bpo-12800: 'tarfile.StreamError: seeking backwards is not allowed' when extract symlink #13217

Closed
wants to merge 2 commits into from

Conversation

websurfer5
Copy link
Contributor

@websurfer5 websurfer5 commented May 9, 2019

Extracting a symlink from a tarball using the tarfile
module in stream mode ('r|') fails with an exception when a file
or symlink of the same name already exists. The fix is to remove
the existing file or symlink before extraction. Tests are included.

https://bugs.python.org/issue12800

module in stream mode ('r|') fails with an exception when a file
or symlink of the same name already exists. The fix is to remove
the existing file or symlink before extraction. Tests are included.
@catlee
Copy link

catlee commented May 13, 2020

Is there a way I can help get this landed? I just ran into this today and wasted a lot of time trying to figure out why my tar file opened in streaming mode was trying to seek backwards.

Copy link
Member

@JulienPalard JulienPalard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea of removing the file / symlink before creating the symlink looks good to me, GNU tar behave the same way.

Please note that GNU tar also removes an empty directory if it exists (but keeps a non-empty directory, and give an error), we may want to copy this too?


@support.skip_unless_symlink
def test_overwrite_symlink(self):
tmpdir = support.temp_cwd('overwrite_symlink')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

temp_cwd is a context manager, please use it in a with statement (also you're not using the variable at all which is strange).

Comment on lines +2521 to +2530
finally:
try:
os.unlink(link)
except:
pass

try:
os.unlink(source)
except:
pass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If using a temporary directory for your test (temp_cwd in a context manager for example), you should not need this at all.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@catlee
Copy link

catlee commented Jun 19, 2020

I've submitted a new PR with the suggested changes: #20972

I have made the requested changes; please review again.

@taleinat
Copy link
Contributor

Thanks for the PR, @websurfer5, but I'm closing this in favor of PR GH-21409, which restores the original fix for this issue which was lost in a bad merge.

@taleinat taleinat closed this Sep 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants