Background
pymonocypher is a Python binding for Monocypher, a small, portable cryptographic library implementing Argon2i key derivation, X25519 key exchange, and ChaCha20-Poly1305 authenticated encryption. Its Argon2i implementation is used to derive encryption keys from passwords — exactly the kind of code path where a memory-safety bug becomes a practical attack surface, since inputs (password, salt, and cost parameters) are frequently attacker-influenced.
Vorthix's autonomous agent selected pymonocypher 4.0.2.6 as a target, built a call graph of the key-derivation surface, and identified argon2i_32() as the highest-priority function: it performs manual pointer arithmetic over a caller-sized work area, driven by two attacker-influenced cost parameters (nb_blocks, nb_iterations).
Root Cause
argon2i_32() computes a block index for each fill step from the nb_blocks parameter, then writes a 128-word (1024-byte) block directly to blocks[index] inside work_area. The function never validates that index is within the bounds of the memory the caller actually allocated for work_area — it trusts that the caller sized the buffer to match nb_blocks exactly. When a caller passes a nb_blocks value larger than the memory it backed work_area with, the computed index runs past the allocation and fill_block() performs an out-of-bounds write.
This is a classic caller/callee contract mismatch: the function signature gives no way to express "this buffer is only N blocks long," so any code path that gets the sizing arithmetic wrong — including reasonable-looking wrapper code — silently corrupts the heap.