Title: gh-143968: Prevent pathlib.Path.copy() from processing special files (FIFO, devices) by tonghuaroot · Pull Request #143966 · python/cpython · GitHub
Open Graph Title: gh-143968: Prevent pathlib.Path.copy() from processing special files (FIFO, devices) by tonghuaroot · Pull Request #143966 · python/cpython
X Title: gh-143968: Prevent pathlib.Path.copy() from processing special files (FIFO, devices) by tonghuaroot · Pull Request #143966 · python/cpython
Description: Closes gh-143968 [3.14] gh-143968: Prevent pathlib.Path.copy() from processing special files (FIFO, devices) Description This PR addresses an issue where pathlib.Path.copy() (introduced for 3.14) could indiscriminately attempt to open and read from special files like FIFOs (named pipes) or character devices (e.g., /dev/zero). The Problem FIFOs: Reading from a FIFO without a writer blocks indefinitely, causing the Python process to hang. Infinite Sources: Reading from /dev/zero results in an infinite loop that continues until disk space is exhausted or the process is killed. The Fix The copy logic in _copy_from inside Lib/pathlib/__init__.py has been modified to explicitly check is_file() before attempting to copy content. If the source is a regular file, it proceeds as normal. If it is a directory (already handled), it recurses. New Behavior: If it is a special file (but exists), it raises io.UnsupportedOperation. This aligns with shutil.copyfile's philosophy of safely handling special files by refusing to copy them as streams. Existing behavior for dangling symlinks (raising FileNotFoundError) is strictly preserved. Tests Added new test cases in Lib/test/test_pathlib/test_copy.py to cover these scenarios: test_copy_fifo: Verifies that copying a FIFO (created via os.mkfifo) raises UnsupportedOperation immediately instead of blocking. test_copy_char_device: Verifies that copying a character device (e.g., /dev/null) raises UnsupportedOperation. Validation Ran python -m test test_pathlib locally and all 1375 tests passed. Issue: gh-143968
Open Graph Description: Closes gh-143968 [3.14] gh-143968: Prevent pathlib.Path.copy() from processing special files (FIFO, devices) Description This PR addresses an issue where pathlib.Path.copy() (introduced for 3.14) c...
X Description: Closes gh-143968 [3.14] gh-143968: Prevent pathlib.Path.copy() from processing special files (FIFO, devices) Description This PR addresses an issue where pathlib.Path.copy() (introduced for 3.14) c...
Opengraph URL: https://github.com/python/cpython/pull/143966
X: @github
Domain: patch-diff.githubusercontent.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:bddc129c-efd1-2e7d-703a-14048306d1d3 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 89D8:20C3D6:C87D4B:108ABE7:696EE59E |
| html-safe-nonce | 92c9c605b95eea553d692e6bacd0102d021173e86ef41cc087b491033623afd3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OUQ4OjIwQzNENjpDODdENEI6MTA4QUJFNzo2OTZFRTU5RSIsInZpc2l0b3JfaWQiOiIyODU4MzQxMjk0NjMzMDUxNTUwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e7960c16bfac3d8aaba528bcd90be918577a6907614c129e881f56695d0fff51 |
| hovercard-subject-tag | pull_request:3184226343 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/143966/files |
| twitter:image | https://avatars.githubusercontent.com/u/23011166?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/23011166?s=400&v=4 |
| og:image:alt | Closes gh-143968 [3.14] gh-143968: Prevent pathlib.Path.copy() from processing special files (FIFO, devices) Description This PR addresses an issue where pathlib.Path.copy() (introduced for 3.14) c... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b278ad162d35332b6de714dfb005de04386c4d92df6475522bef910f491a35ee |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 39aed5006635ab6f45e6b77d23e73b08a00272a3 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width