Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform case-insensitive hash comparisons #12729

Merged
merged 1 commit into from
Jul 9, 2024

Conversation

dtrodrigues
Copy link
Contributor

@dtrodrigues dtrodrigues commented May 25, 2024

This allows packages to be installed when the hash values differ only by case.

Resolves #12680

@dtrodrigues dtrodrigues changed the title Lowercase provided hashes to perform case-insensitive checks Perform case-insensitive hash comparisons May 25, 2024
@@ -82,7 +82,7 @@ def check_against_chunks(self, chunks: Iterable[bytes]) -> None:
hash.update(chunk)

for hash_name, got in gots.items():
if got.hexdigest() in self._allowed[hash_name]:
if got.hexdigest() in [x.lower() for x in self._allowed[hash_name]]:
Copy link
Member

Choose a reason for hiding this comment

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

I feel we should convert more eagerly when the values go into _allowed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had initially lowercased prior to storing in _allowed, but it ends up creating a larger overall change and changes an unrelated test because it loses track of the case of what the user initial supplied, and therefore the error message. If that's preferable, I can go back to that behavior.

Copy link
Contributor Author

@dtrodrigues dtrodrigues Jun 21, 2024

Choose a reason for hiding this comment

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

I updated the code to lowercase the hashes prior to adding them to _allowed.

@uranusjr uranusjr added this to the 24.1 milestone Jun 21, 2024
@uranusjr
Copy link
Member

This fixes a real bug and seems simple enough to be included in 24.1 but I’ll let the RM make the final decision.

@pradyunsg
Copy link
Member

It's a bit late for 24.1 (I cut that yesterday), but we're not that far from 24.2.

@pradyunsg pradyunsg modified the milestones: 24.1, 24.2 Jun 21, 2024
@pradyunsg pradyunsg merged commit d483ff3 into pypa:main Jul 9, 2024
28 checks passed
@pradyunsg
Copy link
Member

Thanks @dtrodrigues! ^.^

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hash comparison is case-sensitive
3 participants