gh-127987: Ensure that directories are not renamed during `tar.TarFile.extractall()` by noamcohen97 · Pull Request #134628 · python/cpython
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.