Title: Prevent array.fromfile reentrancy deadlock in append conversion by Copilot · Pull Request #6576 · RustPython/RustPython · GitHub
Open Graph Title: Prevent array.fromfile reentrancy deadlock in append conversion by Copilot · Pull Request #6576 · RustPython/RustPython
X Title: Prevent array.fromfile reentrancy deadlock in append conversion by Copilot · Pull Request #6576 · RustPython/RustPython
Description: array.fromfile could deadlock when __index__ invoked during element conversion performed a nested append on the same array.
Append conversion before locking: Convert elements (capturing array kind) prior to acquiring the write lock, then push with a runtime invariant check to avoid reentrant deadlocks.
Stronger invariants: Added typed helpers (ArrayType/ArrayElementValue) with assertive mismatch diagnostics to catch unexpected kind/value divergence.
Regression coverage: Extended extra_tests/snippets/stdlib_array.py with a reentrancy scenario where fromfile triggers __index__ that re-appends to the same array.
Example:
import array
a = array.array("b")
class X:
def __index__(self):
a.append(0) # reenters append while fromfile is mid-conversion
return 0
class R:
def read(self, n):
a.append(X())
return b"\0" * n
a.fromfile(R(), 1) # no deadlock; contents now [0, 0, 0]
Original prompt
This section details on the original issue you should resolve
Open Graph Description: array.fromfile could deadlock when __index__ invoked during element conversion performed a nested append on the same array. Append conversion before locking: Convert elements (capturing array kind...
X Description: array.fromfile could deadlock when __index__ invoked during element conversion performed a nested append on the same array. Append conversion before locking: Convert elements (capturing array kind...
Opengraph URL: https://github.com/RustPython/RustPython/pull/6576
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:b9d149b3-c5e2-9ad8-bcda-df5258d72c6b |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | B1B0:3BE5B5:113AC1:16105E:6970173D |
| html-safe-nonce | 5be6ebb0ec8f0c38b524913b07f22a9fc6797d15a86bbd6b1b3ee061afafe4ed |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMUIwOjNCRTVCNToxMTNBQzE6MTYxMDVFOjY5NzAxNzNEIiwidmlzaXRvcl9pZCI6Ijg0MDAzNzM0MjQ3MjYyMTg1NTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 59edf2c85dab8cad6fef323ddc02de3f6c4ca1ece9eb46d7d1e490223a484373 |
| hovercard-subject-tag | pull_request:3134404281 |
| 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/RustPython/RustPython/pull/6576/files |
| twitter:image | https://avatars.githubusercontent.com/in/1143301?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/in/1143301?s=400&v=4 |
| og:image:alt | array.fromfile could deadlock when __index__ invoked during element conversion performed a nested append on the same array. Append conversion before locking: Convert elements (capturing array kind... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 043a09521e81f00c45482046b3f38390b8b292cf9a86ad665a632633a072c05c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git |
| octolytics-dimension-user_id | 39710557 |
| octolytics-dimension-user_login | RustPython |
| octolytics-dimension-repository_id | 135201145 |
| octolytics-dimension-repository_nwo | RustPython/RustPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 135201145 |
| octolytics-dimension-repository_network_root_nwo | RustPython/RustPython |
| 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 | 98881eadf8ae73000970c42161c094b0809b1330 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width