Skip to content

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

Draft
noamcohen97 wants to merge 10 commits intopython:mainfrom
noamcohen97:tar-arbitrary-file-chmod
Draft

gh-127987: Ensure that directories are not renamed during tar.TarFile.extractall()#134628
noamcohen97 wants to merge 10 commits intopython:mainfrom
noamcohen97:tar-arbitrary-file-chmod

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

2 participants