Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_io.BytesIO.getbuffer(): unshare_buffer: Assertion `self->exports == 0' failed #111174

Closed
chgnrdv opened this issue Oct 21, 2023 · 4 comments
Closed
Assignees
Labels
topic-IO type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@chgnrdv
Copy link
Contributor

chgnrdv commented Oct 21, 2023

Crash report

What happened?

import io
f = io.BytesIO()
a = f.getbuffer()
b = f.getbuffer()

Output:

python: ./Modules/_io/bytesio.c:112: unshare_buffer: Assertion `self->exports == 0' failed.
Aborted (core dumped)

Reproduced on 3.8 and 3.11-3.13.

CPython versions tested on:

3.8, 3.11, 3.12, CPython main branch

Operating systems tested on:

Linux

Output from running 'python -VV' on the command line:

Python 3.13.0a1+ (heads/main:11312eae6e, Oct 22 2023, 02:44:38) [GCC 10.2.1 20210110]

Linked PRs

@chgnrdv chgnrdv added the type-crash A hard crash of the interpreter, possibly with a core dump label Oct 21, 2023
@Eclips4
Copy link
Member

Eclips4 commented Oct 22, 2023

cc @serhiy-storchaka as author of unshare_buffer function

@chgnrdv
Copy link
Contributor Author

chgnrdv commented Oct 22, 2023

Docs for BytesIO.getbuffer say that it returns readable and writable view over the buffer of corresponding BytesIO object without copying the contents of this buffer, and that mutating the view updates the buffer it wraps. Should bytesiobuf_getbuffer call unshare_buffer at all in this case, or I am missing something?

@serhiy-storchaka
Copy link
Member

The cause is that empty bytes objects are shared across the interpreter. So Py_REFCNT(self->buf) > 1 even for just created self->buf if it is empty.

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 25, 2023
… BytesIO (pythonGH-111210)

(cherry picked from commit 9da98c0)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 25, 2023
… BytesIO (pythonGH-111210)

(cherry picked from commit 9da98c0)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this issue Oct 25, 2023
…y BytesIO (GH-111210) (GH-111315)

(cherry picked from commit 9da98c0)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this issue Oct 25, 2023
…y BytesIO (GH-111210) (GH-111314)

(cherry picked from commit 9da98c0)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@Eclips4
Copy link
Member

Eclips4 commented Oct 25, 2023

Thanks Radislav for the report and Serhiy for the fix!

@Eclips4 Eclips4 closed this as completed Oct 25, 2023
aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-IO type-crash A hard crash of the interpreter, possibly with a core dump
Projects
None yet
Development

No branches or pull requests

4 participants