Skip to content

bindings/blst.swg: acquire Python memoryview buffers before use - #306

Closed
arib06 wants to merge 1 commit into
supranational:masterfrom
arib06:swig-python-memoryview-getbuffer
Closed

arib06 wants to merge 1 commit into
supranational:masterfrom
arib06:swig-python-memoryview-getbuffer

Conversation

@arib06

@arib06 arib06 commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

acquire the memoryview buffer with PyObject_GetBuffer(PyBUF_SIMPLE) in the points[] and scalars[] typemaps behind P{1,2}_Affines.mult_pippenger, otherwise a released view (heap-use-after-free under ASan) or a negatively strided one like memoryview(b)[::-1] (heap-buffer-overflow, len-1 bytes past the object) reaches blst_p{1,2}s_mult_pippenger;

The points[] and scalars[] typemaps read a memoryview argument through
PyMemoryView_GET_BUFFER() without acquiring it. A released memoryview
keeps its stale Py_buffer, so once mv.release() drops the last reference
to the underlying bytes object the typemap dereferences freed memory. A
negatively strided view such as memoryview(b)[::-1] points buf at the
last byte while len is the full length, so blst_p{1,2}s_mult_pippenger
reads up to len-1 bytes past the end of the object.

Acquire the buffer with PyObject_GetBuffer(PyBUF_SIMPLE), which rejects
released and non-contiguous views, and hold it until freearg.
@dot-asm dot-asm closed this in 2a55b45 Oct 30, 2026
@dot-asm

dot-asm commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants