Skip to content

[crash] librtmp: server-supplied chunk size 0 or negative hangs send thread / drives m_nBytesRead negative #100

Closed

Description

@chriscoveries

A malicious or broken RTMP server can send a Set Chunk Size (type 0x01)
message with a value of 0 or a negative int32. The value is stored
unchecked:

  • plugins/obs-outputs/librtmp/rtmp.c:3600-3608
    HandleChangeChunkSize: r->m_inChunkSize = AMF_DecodeInt32(packet->m_body);
    no validation that the result is > 0.

Consumed at rtmp.c:3949-3963 in RTMP_ReadPacket:

nToRead = packet->m_nBodySize - packet->m_nBytesRead;
nChunk  = r->m_inChunkSize;
if (nToRead < nChunk) nChunk = nToRead;
if (ReadN(r, packet->m_body + packet->m_nBytesRead, nChunk) != nChunk)

ReadN (rtmp.c:1475-1576) loops while (n > 0) and returns
nOriginalSize - n, so for nChunk <= 0 it reads nothing and returns
nChunk itself — the != nChunk error check passes.

Effects:

  • m_inChunkSize == 0: nChunk = 0, m_nBytesRead never advances.
    RTMP_ReadPacket consumes only per-chunk headers and the packet never
    completes — a server that keeps trickling headers wedges
    process_recv_data forever; the send thread can't service stop, so
    stopping the output hangs the streaming stop path.
  • m_inChunkSize < 0: m_nBytesRead decreases each chunk
    (rtmp.c:3972), going negative and moving m_body + m_nBytesRead
    before the allocation; the packet still never completes (same DoS),
    and the corrupted offset is copied into m_vecChannelsIn[]
    (rtmp.c:3975-3977).

Suggested fix: in HandleChangeChunkSize, ignore values < 1 (and
cap the maximum, e.g. > 128 MB), matching the RTMP spec's
1..0x7FFFFFFF range.

Activity

  1. chriscoveries commented on Oct 11, 2026

    @chriscoveries
    ContributorAuthor

    Note on upstream OBS Studio: this bug very likely affects obsproject/obs-studio too. We would report it there, but OBS Studio bans AI-assisted contributions, and in the owner's view they're probably too woke to handle it anyway, so we're keeping it here. Fix: #115.

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

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions