Skip to content

gh-127987: Ensure that directories are not renamed during tar.TarFile.extractall() #134628

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

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

noamcohen97
Copy link
Contributor

@noamcohen97 noamcohen97 commented May 24, 2025

The most straightforward approach to solving this issue is to re-consult the filter_function just before updating the attributes in the directory within extract_all(). However, this would result in stateful extraction filters receiving a redundant call for a file that has already passed the filter.

Inspired by GNU Tar, I decided to save the exact inode number of the created directory to ensure it hasn't changed.
The only downside I can see is that stat() is called shortly after the directory is created, which introduces a race condition. Since the entire module is already susceptible to these kinds of races (the path is resolved in the filter_function and then re-resolved in the actual file creation methods), I believe this is acceptable.

@noamcohen97
Copy link
Contributor Author

@sethmlarson Please let me know what your thoughts are on this one

@noamcohen97 noamcohen97 force-pushed the tar-arbitrary-file-chmod branch from 31dddea to ba8c0f5 Compare May 24, 2025 14:52
@noamcohen97 noamcohen97 force-pushed the tar-arbitrary-file-chmod branch from ba8c0f5 to 0e2d157 Compare May 24, 2025 16:07
it doesn't have to do with this bug
Copy link
Contributor

@sharktide sharktide left a comment

Choose a reason for hiding this comment

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

A news entry would be best here

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.

2 participants