Skip to content

Incorrect behavior of BytesIO.write() when the size of the written data changed during writing #143602

Closed

Description

@serhiy-storchaka

Bug report

There is other bug similar to #143378 in the Python implementation of BytesIO.

The buffer is exported twice for the input data. First, to determine the number of bytes, so we can create a slice when overwriting BytesIO data after seeking. Second, to get the data itself. If the number of bytes different, the underlying bytearray object can be shrinked or expanded, with moving bytes after the current position.

Solution -- we need to use the same exported buffer with memoryview() for the whole writing operation. The test will be slightly more complicated variant of the tests added in #143408.

@superboy-zjc, are you interesting to take this issue? It should be easy to you.

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    stdlibStandard Library Python modules in the Lib/ directory
    3.13only security fixes
    3.14bugs and security fixes
    3.15bugs and security fixes
    on Jan 9, 2026
  2. superboy-zjc commented on Jan 9, 2026

    @superboy-zjc
    Contributor

    @serhiy-storchaka Yes I am working on it.

  3. added 3 commits that reference this issue on Jan 9, 2026
  4. added a commit that references this issue on Jan 15, 2026
  5. added 3 commits that reference this issue on Jan 15, 2026
  6. added a commit that references this issue on Feb 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13only security fixes3.14bugs and security fixes3.15bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-IOtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions