Skip to content

gh-157190: Follow symlinks when extracting tarfile hard links - #157191

Merged
encukou merged 4 commits into
python:mainfrom
StanFromIreland:sneaky_hardlink_relocation
Sep 10, 2026
Merged

encukou merged 4 commits into
python:mainfrom
StanFromIreland:sneaky_hardlink_relocation

Conversation

@StanFromIreland

@StanFromIreland StanFromIreland commented Sep 8, 2026 •

Copy link
Copy Markdown
Member
@StanFromIreland StanFromIreland added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 8, 2026
@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @StanFromIreland for commit 027cfba 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F157191%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 8, 2026

@encukou encukou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM; let's merge if the buildbots or the 3.13 backport don't fail in tarfile.
When merging: the commit message should mention that the fixed bug only exists in 3.13 and below.

Comment thread Lib/tarfile.py Resolved
Comment thread Lib/test/test_tarfile.py

@symlink_test
@os_helper.skip_unless_hardlink
def test_sneaky_hardlink_relocation(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we want to test also a symlink pointing to a directory?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not sure what that would be testing, a hard link to a directory isn't possible.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I meant a hard link to the symlink, where the symlink points to a directory.

Something like that:

2026-09-09T17:26:21.505759000+0200 maurycy@gimel /tmp/tarararara  % tar tvf evil.tar
drw-r--r--  0 0      0           0 Jan  1  1970 a/d/
-rw-r--r--  0 0      0           5 Jan  1  1970 a/d/f
lrw-r--r--  0 0      0           0 Jan  1  1970 a/b/s -> ../d
hrw-r--r--  0 0      0           0 Jan  1  1970 s link to a/b/s

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

os.link() raises on a directory, so it falls through to the fallback branch, which is the path test_sneaky_hardlink_fallback_deep covers.

Co-authored-by: Maurycy Pawłowski-Wieroński <maurycy@maurycy.com>
@encukou
encukou merged commit b38be2e into python:main Sep 10, 2026
51 checks passed
@encukou encukou added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Sep 10, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @StanFromIreland for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Thanks @StanFromIreland for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Sep 10, 2026

Copy link
Copy Markdown

GH-157261 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Sep 10, 2026
@bedevere-app

bedevere-app Bot commented Sep 10, 2026

Copy link
Copy Markdown

GH-157262 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Sep 10, 2026
encukou pushed a commit that referenced this pull request Sep 10, 2026
…k to a symlink (GH-157191)  (GH-157192)

(cherry picked from commit 480ea4a)
The backport to 3.13 and below includes a NEWS entry.

Co-authored-by: Stan Ulbrych <stan@python.org>
@bedevere-bot

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot PPC64LE Fedora Stable LTO + PGO 3.13 (tier-2) has failed when building commit b8f23e3.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1494/builds/1358) and take a look at the build logs.
  4. Check if the failure is related to this commit (b8f23e3) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1494/builds/1358

Failed tests:

  • test_smtpnet

Failed subtests:

  • test_explicit_connect_host_port_starttls - test.test_smtpnet.SmtpTest.test_explicit_connect_host_port_starttls
  • test_connect_host_port_starttls - test.test_smtpnet.SmtpTest.test_connect_host_port_starttls

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-ppc64le/3.13.cstratak-fedora-stable-ppc64le.lto-pgo/build/Lib/test/test_smtpnet.py", line 54, in test_connect_host_port_starttls
    server = smtplib.SMTP(f'{self.testServer}:{self.remotePort}')
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-ppc64le/3.13.cstratak-fedora-stable-ppc64le.lto-pgo/build/Lib/smtplib.py", line 266, in __init__
    raise SMTPConnectError(code, msg)
smtplib.SMTPConnectError: (421, b'4.4.5 Server busy, try again later. (smtp.gmail.com)\n4.4.5  For more information, go to\n4.4.5  https://support.google.com/a/answer/3221692 5b1f17b1804b1-49d1fb058c9sm1436945e9.0 - gsmtp')


Traceback (most recent call last):
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-ppc64le/3.13.cstratak-fedora-stable-ppc64le.lto-pgo/build/Lib/test/test_smtpnet.py", line 92, in test_explicit_connect_host_port_starttls
    server.starttls(context=context)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-ppc64le/3.13.cstratak-fedora-stable-ppc64le.lto-pgo/build/Lib/smtplib.py", line 783, in starttls
    self.ehlo_or_helo_if_needed()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-ppc64le/3.13.cstratak-fedora-stable-ppc64le.lto-pgo/build/Lib/smtplib.py", line 620, in ehlo_or_helo_if_needed
    if not (200 <= self.ehlo()[0] <= 299):
                   ~~~~~~~~~^^
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-ppc64le/3.13.cstratak-fedora-stable-ppc64le.lto-pgo/build/Lib/smtplib.py", line 461, in ehlo
    (code, msg) = self.getreply()
                  ~~~~~~~~~~~~~^^
  File "/var/lib/buildbot/worker/cstratak-fedora-stable-ppc64le/3.13.cstratak-fedora-stable-ppc64le.lto-pgo/build/Lib/smtplib.py", line 414, in getreply
    raise SMTPServerDisconnected("Connection unexpectedly closed")
smtplib.SMTPServerDisconnected: Connection unexpectedly closed
@bedevere-app

bedevere-app Bot commented Sep 29, 2026

Copy link
Copy Markdown

GH-158455 is a backport of this pull request to the 3.11 branch.

freakboy3742 pushed a commit to freakboy3742/cpython that referenced this pull request Sep 29, 2026
…rd link to a symlink (pythonGH-157191)

The backport to 3.13 and below includes a NEWS entry.
(cherry picked from commit b8f23e3)

Co-authored-by: Stan Ulbrych <stan@python.org>
@bedevere-app

bedevere-app Bot commented Sep 29, 2026

Copy link
Copy Markdown

GH-158457 is a backport of this pull request to the 3.10 branch.

pablogsal pushed a commit that referenced this pull request Sep 29, 2026
…k to a symlink (GH-157191) (#158457)

The backport to 3.13 and below includes a NEWS entry.


(cherry picked from commit b8f23e3)

Co-authored-by: Stan Ulbrych <stan@python.org>
pablogsal pushed a commit that referenced this pull request Sep 29, 2026
…k to a symlink (GH-157191) (#158455)

The backport to 3.13 and below includes a NEWS entry.
(cherry picked from commit b8f23e3)

Co-authored-by: Stan Ulbrych <stan@python.org>
StanFromIreland added a commit that referenced this pull request Sep 30, 2026
GH-157191) (#157261)

(cherry picked from commit b38be2e)

Co-authored-by: Stan Ulbrych <stan@python.org>
Yhg1s pushed a commit that referenced this pull request Sep 30, 2026
…k to a symlink (GH-157191)  (GH-157192) (#157454)

* [3.12] gh-157190: Fix tarfile `data`/`tar` filter bypass via hard link to a symlink (GH-157191)  (GH-157192)

(cherry picked from commit 480ea4a)
The backport to 3.13 and below includes a NEWS entry.
(cherry picked from commit b8f23e3)

Co-authored-by: Stan Ulbrych <stan@python.org>
Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
serhiy-storchaka pushed a commit that referenced this pull request Oct 10, 2026
GH-157191) (GH-157262)

(cherry picked from commit b38be2e)

Co-authored-by: Stan Ulbrych <stan@python.org>
icanhasmath pushed a commit to ActiveState/cpython that referenced this pull request Oct 28, 2026
…rd link to a symlink (pythonGH-157191) (python#158457)

The backport to 3.13 and below includes a NEWS entry.

(cherry picked from commit b8f23e3)

Co-authored-by: Stan Ulbrych <stan@python.org>
(cherry picked from commit 197663d)

3.9.25.x: 3.9 has no test.support.os_helper; can_hardlink() and
skip_unless_hardlink() are added to test.support next to
skip_unless_symlink() instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

4 participants