[New-bugs-announce] [issue36519] Blake2b/s implementations have minor GIL issues

George King report at bugs.python.org
Wed Apr 3 11:04:35 EDT 2019


New submission from George King <george.w.king at gmail.com>:

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.

----------
components: Extension Modules
messages: 339394
nosy: gwk
priority: normal
severity: normal
status: open
title: Blake2b/s implementations have minor GIL issues
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36519>
_______________________________________


More information about the New-bugs-announce mailing list