Skip to content

ShareableList: an empty str/bytes gets a zero-length slot and silently overwrites its neighbour #163051

Backlog

Description

@hyongtao-code

Bug report

An empty str or bytes in ShareableList is allocated zero bytes, so it shares its offset with the next item — or with the packing-format metadata when it is the last item. Writing to that slot either raises a misleading ValueError or silently corrupts adjacent data.

Reproducer

from multiprocessing.shared_memory import ShareableList

sl = ShareableList(["", 42])
sl[0] = 7
print(list(sl))

sl.shm.close()
sl.shm.unlink()

Wrong result

D:\MyCode\cpython> .\PCbuild\amd64\python_d.exe .\main_shared_list.py
[7, 7]

Analysis

Regression from 9348e13 (gh-88336 / GH-26328): ceil(len / 8) is 0 for an empty str/bytes, so the item shares its offset with the next item (or the format metadata) and is silently overwritten.

Unlike gh-145261 and gh-106939, the slot layout itself is wrong here, and the corruption only surfaces on write.

Affected versions

python 3.16.0a2 / main only.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Linked PRs

Activity

  1. added
    type-bug
    on Dec 3, 2026
  2. added
    stdlib
    on Dec 3, 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

    stdlibtopic-multiprocessingtype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions