Skip to content

gh-131316: handle NULL values returned by HACL* functions #131324

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

Merged
merged 4 commits into from
Mar 17, 2025

Conversation

picnixz
Copy link
Member

@picnixz picnixz commented Mar 16, 2025

In a follow-up PR I'd like to move all UPDATE functions in a single helper. The construction is always the same and it would help the HMAC PR as well (I've done it out there).

More generally, I'd like to have the same construction for MD5/SHA1/SHA2/SHA3 as they really share common code. I don't know how much I can change the code so that it looks better, which is why I didn't change anything here.

We had a discussion on the blake2 PR concerning the cosmetics of blake2module and I think we can definitely improve how it's currently structured, because the functions become quite ugly. But that'd be another issue.

cc @msprotz @chris-eibl

- Handle NULL returned by allocation functions.
- Handle NULL returned by copy functions.
- Suppress unused impossible return codes.
@chris-eibl
Copy link
Member

assert((Py_ssize_t)(LEN) <= (Py_ssize_t)UINT32_MAX);

Most probably you've already found out: Py_ssize_t is only signed 32bit in 32bit platforms (same for Windows and Linux).
Hence, (Py_ssize_t)UINT32_MAX gets negative and the assert always fires:
https://godbolt.org/z/1K1v5r6db

@picnixz
Copy link
Member Author

picnixz commented Mar 16, 2025

Hence, (Py_ssize_t)UINT32_MAX gets negative and the assert always fires:

Yeah... that's what I observed afterwards... so I just removed the assertion (can't fail if the assertion isn't here 😈)

@gpshead
Copy link
Member

gpshead commented Mar 16, 2025

FWIW it is quite reasonable for these update loops to use a size lower than UINT32_MAX, by the time data gets that large the computation already takes a long time so just looping over 1-2gb chunks up to INT32_MAX to fit within our smallest signed size constraint is fine.

@picnixz picnixz self-assigned this Mar 16, 2025
@picnixz picnixz merged commit 261633b into python:main Mar 17, 2025
45 checks passed
@picnixz picnixz deleted the feat/mods/handle-hacl-error-codes-131316 branch March 17, 2025 10:10
plashchynski pushed a commit to plashchynski/cpython that referenced this pull request Mar 17, 2025
…on#131324)

- Handle NULL returned by allocation functions.
- Handle NULL returned by copy functions.
- Suppress unused impossible return codes.
seehwan pushed a commit to seehwan/cpython that referenced this pull request Apr 16, 2025
…on#131324)

- Handle NULL returned by allocation functions.
- Handle NULL returned by copy functions.
- Suppress unused impossible return codes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants