Skip to content

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

Closed

Description

@chgnrdv

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

Activity

  1. added
    type-crashA hard crash of the interpreter, possibly with a core dump
    on Oct 21, 2023
  2. Eclips4 commented on Oct 22, 2023

    @Eclips4
    Member

    cc @serhiy-storchaka as author of unshare_buffer function

  3. chgnrdv commented on Oct 22, 2023

    @chgnrdv
    ContributorAuthor

    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?

  4. added a commit that references this issue on Oct 23, 2023
  5. serhiy-storchaka commented on Oct 23, 2023

    @serhiy-storchaka
    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.

  6. added a commit that references this issue on Oct 25, 2023
  7. added 2 commits that reference this issue on Oct 25, 2023
  8. added 2 commits that reference this issue on Oct 25, 2023
  9. Eclips4 commented on Oct 25, 2023

    @Eclips4
    Member

    Thanks Radislav for the report and Serhiy for the fix!

  10. added a commit that references this issue on Feb 11, 2024
  11. added a commit that references this issue on Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

topic-IOtype-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