Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/tiran'closed_at=Nonecreated_at=<Date2019-04-03.15:04:35.230>labels= ['extension-modules', '3.8', 'type-bug', '3.7']
title='Blake2b/s implementations have minor GIL issues'updated_at=<Date2019-04-03.15:20:57.965>user='https://github.com/gwk'
I was browsing the Blake2b module implementation in master and noticed two subtle issues in blake2b_impl.c. There are two places where the GIL gets released; both of them appear flawed.
py_blake2b_new_impl, line 221. The ALLOW_THREADS block fails to acquire/release self->lock.
_blake2_blake2b_update, line 279. The lock is lazily allocated correctly on line 279. However the test on 282 that chooses to release the GIL or not fails to take into account the length test. This means that once a large block is fed to update, then every call to update will release the GIL, even if it is a single byte.
Activity
gwk commented on Apr 3, 2019
I was browsing the Blake2b module implementation in master and noticed two subtle issues in blake2b_impl.c. There are two places where the GIL gets released; both of them appear flawed.
py_blake2b_new_impl, line 221. The ALLOW_THREADS block fails to acquire/release self->lock.
_blake2_blake2b_update, line 279. The lock is lazily allocated correctly on line 279. However the test on 282 that chooses to release the GIL or not fails to take into account the length test. This means that once a large block is fed to update, then every call to update will release the GIL, even if it is a single byte.
It should look something more like this:
bool should_allow_threads = (buf.len >= HASHLIB_GIL_MINSIZE); if (should_allow_threads && self->lock == NULL) self->lock = PyThread_allocate_lock(); if (should_allow_threads && self->lock != NULL) { ... } else { ... }This respects the size criterion, and also protects against the case where the lock allocation fails.
tiran commented on Apr 3, 2019
Thanks, I'll have a look.
picnixz commented on Jul 15, 2025
This has been fixed by #135267.