Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

segfault in mmap object when using __index__ method that closes the mmap #103987

Closed
Labels
3.11only security fixes3.12only security fixes3.13bugs and security fixesextension-modulesC modules in the Modules dirtype-crashA hard crash of the interpreter, possibly with a core dump
@cfbolz

Description

@cfbolz

The following (artificial) code segfaults CPython (I tried a bunch of versions, including git main) on my x86 Ubuntu Linux 22.10:

importmmapwithopen("abcds","w+")asf:f.write("foobar")f.flush()classX(object):def__index__(self):m.close()return1m=mmap.mmap(f.fileno(),6,access=mmap.ACCESS_READ)print(m[1])print(m[X()])

The problem is this code inmmapmodule.c

staticPyObject*mmap_subscript(mmap_object*self,PyObject*item){CHECK_VALID(NULL);if (PyIndex_Check(item)) {Py_ssize_ti=PyNumber_AsSsize_t(item,PyExc_IndexError);if (i==-1&&PyErr_Occurred())returnNULL;if (i<0)i+=self->size;if (i<0||i >=self->size) {PyErr_SetString(PyExc_IndexError,"mmap index out of range");returnNULL;        }returnPyLong_FromLong(Py_CHARMASK(self->data[i]));...

theCHECK_VALID(NULL) call which checks whether the mmap object is closed happens before thePyNumber_AsSsize_t call which closes the object (and similarly for the slice handling which happens further down).

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixes3.12only security fixes3.13bugs and security fixesextension-modulesC modules in the Modules dirtype-crashA hard crash of the interpreter, possibly with a core dump

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp