Skip to content

.ipc._shm._shorten_key_for_macos() may cause collisions for short names? #423

@goodboy

Description

@goodboy

From copilot's review in #406.

I'm adding this as a follow up since what we have in #406 is more
then good enough imo for a first macos-support attempt and given that
the .ipc._shm subsys is currently undocumented and still considered
somewhat unrefined/experimental.


_shorten_key_for_macos() ignores the provided prefix/suffix
when len(key) <= max_len (it returns key unchanged). This causes
collisions on macOS in _make_token() because shm_name,
shm_first_index_name, and shm_last_index_name can become
identical for “short” keys, and it also drops the prefix for
open_shm_list(). Adjust the early-return logic to include `prefix

  • key + suffixand ensure the length check accounts for the leading '/' added bySharedMemory` on POSIX as well as the prefix/suffix
    lengths.
    # Account for the leading '/' added by POSIX SharedMemory names
    usable_len: int = max_len - 1
    full_key: str = f"{prefix}{key}{suffix}"
    if len(full_key) <= usable_len:
        return full_key

    _hash: str = hashlib.sha256(
        key.encode()
    ).hexdigest()

    hash_len: int = (
        usable_len

Metadata

Metadata

Assignees

No one assigned

    Labels

    lo IPClocalhost IPC primitives and APIsmacos_relatedgotta tailor to them job bros i supposenon-linuxfor those who prefer walled gardens (macos, windows, etc.)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions