Skip to content

Comments

fix: support pid > 65535#669

Open
apopov-app wants to merge 1 commit intoTelegramMessenger:masterfrom
apopov-app:fix/pid-32bit
Open

fix: support pid > 65535#669
apopov-app wants to merge 1 commit intoTelegramMessenger:masterfrom
apopov-app:fix/pid-32bit

Conversation

@apopov-app
Copy link

@apopov-app apopov-app commented Feb 14, 2026

Problem

MTProxy crashed due to assert (!(p & 0xffff0000)) in init_common_PID: the code assumed PID always fits in 16 bits. On systems with pid_max > 65535 (e.g. pid 94936, 95241), the assert triggered
and the proxy crashed.

Solution (workaround)

Removed the assert and store only the lower 16 bits of the PID instead of the full value:

PID.pid = (unsigned short) (p & 0xffff);

Why not 32 bits

This is a workaround. Ideally we would pass a 32-bit pid, but that is not possible:

  • process_id is serialized in the RPC handshake between MTProxy and Telegram DC servers
  • The packet format is fixed: 32 bytes, pid is 16 bits
  • We cannot change Telegram servers or the protocol
  • With a 32-bit pid, the handshake size grows from 32 to 40 bytes — DC expects 32, so the protocol breaks
    So we only have truncation: instead of a crash, there may be pid collisions when pid > 65535 (rarely critical for MTProxy).

Co-authored-by: Cursor <cursoragent@cursor.com>
@apopov-app apopov-app changed the title fix: extend pid field to 32-bit (getpid returns 32-bit on modern systems) fix: support pid > 65535 Feb 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant