Skip to content

Conversation

@AZero13
Copy link
Contributor

@AZero13 AZero13 commented Jan 19, 2026

fd_and_follow_symlinks_invalid lets you use fd and follow_symlinks together if fd is 0.

This is incorrect, as 0 is a valid fd.

@AZero13 AZero13 changed the title posixmodule: fd_and_follow_symlinks_invalid lets fd be 0 gh-144023: fd_and_follow_symlinks_invalid lets fd be 0 Jan 19, 2026
@AZero13 AZero13 force-pushed the careful branch 2 times, most recently from 5e70bef to b253e1e Compare January 19, 2026 05:58
@AZero13 AZero13 changed the title gh-144023: fd_and_follow_symlinks_invalid lets fd be 0 gh-144023: prevent follow_symlinks from being allowed with an fd of 0 Jan 19, 2026
Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Is there any way to test this?

@vstinner
Copy link
Member

Is there any way to test this?

stat(0) can be be used for example.

Current behavior:

>>> os.stat(1, follow_symlinks=False)
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    os.stat(1, follow_symlinks=False)
    ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: stat: cannot use fd and follow_symlinks together

>>> os.stat(0, follow_symlinks=False)
os.stat_result(st_mode=8576, st_ino=4, st_dev=27, st_nlink=1, st_uid=1000, st_gid=5, st_size=0, st_atime=1768842168, st_mtime=1768842168, st_ctime=1768841838)

…d of 0

fd_and_follow_symlinks_invalid lets you use fd and follow_symlinks together if fd is 0.

This is incorrect, as 0 is a valid fd.
@AZero13
Copy link
Contributor Author

AZero13 commented Jan 19, 2026

Is there any way to test this?

stat(0) can be be used for example.

Current behavior:

>>> os.stat(1, follow_symlinks=False)
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    os.stat(1, follow_symlinks=False)
    ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: stat: cannot use fd and follow_symlinks together

>>> os.stat(0, follow_symlinks=False)
os.stat_result(st_mode=8576, st_ino=4, st_dev=27, st_nlink=1, st_uid=1000, st_gid=5, st_size=0, st_atime=1768842168, st_mtime=1768842168, st_ctime=1768841838)

Thank you!

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

Good catch. LGTM. 👍

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Thank you!

@sobolevn sobolevn added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Jan 20, 2026
@serhiy-storchaka serhiy-storchaka merged commit fa44efa into python:main Jan 20, 2026
55 checks passed
@miss-islington-app
Copy link

Thanks @AZero13 for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@miss-islington-app
Copy link

Sorry, @AZero13 and @serhiy-storchaka, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker fa44efa0ef1972ac1e2f66996303154be11f605e 3.14

@miss-islington-app
Copy link

Sorry, @AZero13 and @serhiy-storchaka, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker fa44efa0ef1972ac1e2f66996303154be11f605e 3.13

@AZero13 AZero13 deleted the careful branch January 20, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants