Skip to content

bindings/python: bump PyO3 to 0.29.0 to remediate GHSA-36hh-v3qg-5jq4#752

Merged
anakrish merged 2 commits into
mainfrom
copilot/fix-pyo3-out-of-bounds-read
Jun 24, 2026
Merged

bindings/python: bump PyO3 to 0.29.0 to remediate GHSA-36hh-v3qg-5jq4#752
anakrish merged 2 commits into
mainfrom
copilot/fix-pyo3-out-of-bounds-read

Conversation

Copilot AI commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

PyO3 versions before 0.29.0 contain an out-of-bounds read vulnerability in optimized nth / nth_back implementations for PyList / PyTuple iterators. This PR applies the minimum patched version in the affected manifest (bindings/python/Cargo.lock context) to clear the high-severity advisory with minimal change surface.

  • Dependency remediation

    • Updated bindings/python/Cargo.toml from pyo3 = 0.28.3 to pyo3 = 0.29.0 (lowest patched version).
    • Regenerated bindings/python/Cargo.lock via Cargo tooling, updating:
      • pyo3 0.28.3 -> 0.29.0
      • pyo3-build-config 0.28.3 -> 0.29.0
      • pyo3-ffi 0.28.3 -> 0.29.0
      • pyo3-macros 0.28.3 -> 0.29.0
      • pyo3-macros-backend 0.28.3 -> 0.29.0
  • Reachability Assessment

    • The advisory targets Iterator::nth / DoubleEndedIterator::nth_back on PyO3 list/tuple iterators.
    • In bindings/python/src/lib.rs, list/tuple handling uses straightforward for v in plist / for v in ptuple iteration; there are no direct calls to nth or nth_back in this binding.
    • Assessment: vulnerable code path is not directly reachable from repository code paths identified.
    • Risk statement: this update is primarily to satisfy vulnerability scanners and prevent latent exposure through transitive/internal iterator behavior.
    • Confidence: high (specific APIs were named in the advisory and repository-wide checks of Python binding code found no direct usage).
# bindings/python/Cargo.toml
pyo3 = { version = "0.29.0", features = ["abi3-py310", "anyhow", "extension-module"] }
Original prompt

This section details the Dependabot vulnerability alert you should resolve

<alert_title>PyO3 has an Out-of-bounds Read in nth / nth_back for PyList and PyTuple iterators</alert_title>
<alert_description>PyO3 0.24.0 added optimized implementations of Iterator::nth and DoubleEndedIterator::nth_back for the BoundListIterator and BoundTupleIterator types. These implementations computed the target index using unchecked usize addition (index + n) before bounds-checking against the sequence length, then read the element via get_item_unchecked.

In nth methods, a sufficiently large n (combined with a non-zero internal index) could cause the addition to overflow and wrap around, producing a small "target index" that passed the bounds check and enabling reads at the front of the list or tuple of elements previously yielded by the iterator.

In nth_back methods, a sufficiently large n could cause underflow in a similar fashion, however would instead allow reads of arbitrary memory past the end of the list or tuple storage.</alert_description>

high
GHSA-36hh-v3qg-5jq4
pyo3
rust
<vulnerable_versions>= 0.28.3</vulnerable_versions>
<patched_version>0.29.0</patched_version>
<manifest_path>bindings/python/Cargo.lock</manifest_path>

https://github.com/PyO3/pyo3/pull/6086 https://rustsec.org/advisories/RUSTSEC-2026-0176.html https://github.com/advisories/GHSA-36hh-v3qg-5jq4

<agent_instructions>Look at how other projects have addressed this and implement a similar fix.</agent_instructions>

<task_instructions>Resolve this alert by updating the affected package to a non-vulnerable version. Prefer the lowest non-vulnerable version (see the patched_version field above) over the latest to minimize breaking changes. Include a Reachability Assessment section in the PR description. Review the alert_description field to understand which APIs, features, or configurations are affected, then search the codebase for usage of those specific items. If the vulnerable code path is reachable, explain how (which files, APIs, or call sites use the affected functionality) and note that the codebase is actively exposed to this vulnerability. If the vulnerable code path is not reachable, explain why (e.g. the affected API is never called, the vulnerable configuration is not used) and note that the update is primarily to satisfy vulnerability scanners rather than to address an active risk. If the advisory is too vague to determine reachability (e.g. 'improper input validation' with no specific API named), state that reachability could not be determined and explain why. Include a confidence level in the reachability assessment (e.g. high confidence if the advisory names a specific API and you confirmed it is or is not called, low confidence if the usage is indirect and hard to trace). If no patched version is available, check the alert_description field for a Workarounds section — the advisory may describe configuration changes or usage patterns that mitigate the vulnerability without a version update. If a workaround is available, apply it and leave a code comment referencing the advisory identifier explaining it is a temporary mitigation. If neither a patch nor a workaround is available, explain in the PR description why the alert cannot be resolved automatically so a human reviewer can take over. Inspect the repository to determine which package manager is used (e.g. lock files, config files, build scripts) and use that tooling to perform the update — do not edit lock files directly. If the version constraint in the manifest (e.g. package.json, Gemfile, pyproject.toml) caps the version below the fix, update the constraint first. For transitive dependencies, determine whether it is simpler to update the direct dependency that pulls in the vulnerable package or to update the transitive dependency directly, and choose the least disruptive approach. If upgrading to fix the vulnerability forces a major version bump or known breaking changes, review the changelog or release notes, then audit the codebase for usage of affected APIs and fix any breaking changes that are found. If the package manager fails to resolve dependencies (e.g. peer dependency conflicts, incompatible engine constraints), document the error in the PR description rather than attempting increasingly complex workarounds. After updating, check the lock file to confirm the package no longer resolves to a version in the vulnerable range. Keep changes minimal and tightly scoped. Ensure tests, build, type checking, and linting all pass after your changes. If there are any test, lint, or typechecking failures, investigate whether they are caused by the update and fix them if so — do not leave broken tests in the PR. If they were already present before the update, note them in the PR descript...

Copilot AI changed the title [WIP] Fix out-of-bounds read in PyO3 iterator methods bindings/python: bump PyO3 to 0.29.0 to remediate GHSA-36hh-v3qg-5jq4 Jun 23, 2026
Copilot AI requested a review from anakrish June 23, 2026 15:13
@anakrish anakrish marked this pull request as ready for review June 23, 2026 16:17
@anakrish anakrish merged commit 4b8874b into main Jun 24, 2026
59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants