Skip to content

fix: match index hashes against per-file lock entries - #11131

Merged
radoering merged 3 commits into
python-poetry:mainfrom
jipeng6036-del:fix/11130-mixed-index-hashes
Oct 31, 2026
Merged

radoering merged 3 commits into
python-poetry:mainfrom
jipeng6036-del:fix/11130-mixed-index-hashes

Conversation

@jipeng6036-del

@jipeng6036-del jipeng6036-del commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Pull Request Check List

Resolves: #11130

  • Added tests for changed code.
  • Updated documentation for changed code.

Summary

The chooser collects locked hash algorithms across all files in a package. If a PEP 691 index advertises both sha256 and sha512 for a wheel locked with sha256, another file's sha512 lock entry makes the chooser select the wrong algorithm and reject the wheel.

Scope locked_hashes and locked_hash_names to each candidate filename. Keep selecting the highest-priority shared algorithm and computing sha256 when no shared algorithm is advertised. This also prevents a candidate from being accepted using a digest locked for a different file.

The tests cover mixed algorithms across files, mismatched digests, the highest-priority digest when a file has multiple locked hashes, and cross-file hash rejection. No documentation change is needed for this internal selection fix.

Validation

  • Windows / Python 3.13.12: chooser tests 66 passed; full poetry run mypy passed for 380 source files; pre-commit checks on both changed files and git diff --check passed.
  • Running the revised tests against the previous implementation produced 3 failures / 63 passes, covering lower-priority acceptance, cross-file acceptance, and the file-specific diagnostic.
  • Full poetry run pytest --integration -n 4 -q: 3354 passed, 7 failed, 15 skipped, 2 xfailed. This is not a clean full-suite result. An unchanged 78f5e2b checkout with the same interpreter/dependencies had 3355 passed, 3 failed, 15 skipped, 2 xfailed; its failures cover symlink installation, extension compilation, and executable discovery. The other four failures were reproduced together on that unchanged checkout by running the existing env use test before the three interpreter-discovery tests, which retain a mocked /prefix result in findpython's cache. Those three discovery tests pass when run independently on the updated code. No environment tests or test configuration were changed.
  • Earlier Linux baseline comparison: run 37767632697 used exact Python 3.10.22/3.12.15 versions and found the same archive symlink-test failure on upstream 63bba27 and previous PR head 78f5e2b. That run predates this update; the latest hosted checks must be evaluated separately.
  • Latest hosted Tests run 38280321603 on 93ab883 completed successfully: 56 jobs passed, 3 skipped, including all Linux/Windows/macOS pytest, mypy and plugin-export jobs across Python 3.10–3.15. The skipped jobs are the unchanged lockfile, fixture-generation and build-smoke gates.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Needs a human reviewer. If the hash-selection logic is wrong, the chooser could silently accept and install an artifact that does not match the intended lock entry, potentially allowing malicious package code to run. Reverting would stop future incorrect selections but would not undo artifacts already installed under the faulty trust decision.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/poetry/installation/chooser.py Resolved
@jipeng6036-del jipeng6036-del changed the title fix: accept any matching hash from PEP 691 JSON indexes fix: match index hashes against per-file lock entries Oct 12, 2026
When a package lock entry mixes hash algorithms, choosing only the
highest-priority advertised hash skipped files whose locked digest
was still listed on the index.

Fixes python-poetry#11130
@radoering
radoering force-pushed the fix/11130-mixed-index-hashes branch from 93ab883 to d38bee3 Compare October 31, 2026 13:58

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Linked issues

#11130 poetry install skips valid files when a package's lock entry mixes sha256 and sha512 (JSON index) · 0 of 1 met

# Requirement Status Notes
1 Accept an advertised hash that matches the locked hash for that file. 🟡 Partly met The change scopes locked hashes to the candidate filename, but checks only the highest-priority shared algorithm when that file has multiple locked hashes.

Comment thread src/poetry/installation/chooser.py Resolved
@radoering
radoering merged commit b1e370b into python-poetry:main Oct 31, 2026
52 checks passed
radoering pushed a commit that referenced this pull request Nov 21, 2026
mwalbeck pushed a commit to mwalbeck/docker-python-poetry that referenced this pull request Nov 28, 2026
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [poetry](https://github.com/python-poetry/poetry) ([changelog](https://python-poetry.org/history/)) | patch | `2.5.1` → `2.5.2` |

---

### Release Notes

<details>
<summary>python-poetry/poetry (poetry)</summary>

### [`v2.5.2`](https://github.com/python-poetry/poetry/blob/HEAD/CHANGELOG.md#252---2026-11-21)

[Compare Source](python-poetry/poetry@2.5.1...2.5.2)

##### Changed

- Allow `pkginfo>=2.0` ([#&#8203;11239](python-poetry/poetry#11239)).
- Report a comprehensible error if a configured repository is missing a URL ([#&#8203;11081](python-poetry/poetry#11081),
  [#&#8203;11114](python-poetry/poetry#11114),
  [#&#8203;11242](python-poetry/poetry#11242)).
- Report a comprehensible error for an invalid `--priority` in `poetry source add` instead of failing with a `KeyError` ([#&#8203;11175](python-poetry/poetry#11175)).

##### Fixed

- Fix an issue where `poetry install` built an sdist before checking it against its lock file hash ([#&#8203;11253](python-poetry/poetry#11253)).
- Fix an issue where `poetry install` rejected a distribution even though one of the hashes provided by the package index matched the hash locked for that file. ([#&#8203;11131](python-poetry/poetry#11131)).
- Fix an issue where uninstalling a path dependency failed if its source did not exist anymore ([#&#8203;11093](python-poetry/poetry#11093)).
- Fix an issue where `poetry version prerelease` failed for a dev release ([#&#8203;11217](python-poetry/poetry#11217)).

##### Docs

- Document the options of `poetry debug resolve` ([#&#8203;11211](python-poetry/poetry#11211)).
- Clarify `solver.min-release-age-exclude` and `solver.min-release-age-exclude-source` ([#&#8203;11087](python-poetry/poetry#11087)).
- Distinguish package and upload repository URLs ([#&#8203;11143](python-poetry/poetry#11143)).
- Explain the certificate configuration for system Git ([#&#8203;11145](python-poetry/poetry#11145)).
- Add separate directory and archive path dependency examples ([#&#8203;11079](python-poetry/poetry#11079)).
- Use the plugin repository for the `poetry-export` pre-commit hook ([#&#8203;11213](python-poetry/poetry#11213)).
- Fix the incorrect `tool.poetry` section name in the FAQ ([#&#8203;11150](python-poetry/poetry#11150)).

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4yNjAuMCIsInVwZGF0ZWRJblZlciI6IjQzLjI2MC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

Reviewed-on: https://git.walbeck.it/mwalbeck/docker-python-poetry/pulls/1778
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.

poetry install skips valid files when a package's lock entry mixes sha256 and sha512 (JSON index)

2 participants