Skip to content

librtmp: Ignore invalid chunk sizes from the server - #119

Closed
b7216309-jpg wants to merge 2 commits into
obs-rust:masterfrom
b7216309-jpg:fix/rtmp-chunk-size
Closed

b7216309-jpg wants to merge 2 commits into
obs-rust:masterfrom
b7216309-jpg:fix/rtmp-chunk-size

Conversation

@b7216309-jpg

Copy link
Copy Markdown
Contributor

Fixes #100.

HandleChangeChunkSize stored the server's Set Chunk Size value in the int m_inChunkSize unchecked. RTMP_ReadPacket reads min(remaining, m_inChunkSize) bytes per chunk, and ReadN returns n unchanged for n <= 0, so its error check passes:

  • 0: no chunk adds to the packet, which never completes; the send thread keeps reading chunk headers instead of stopping
  • bit 31 set: the size is negative and m_nBytesRead goes backwards, below the body allocation

Change

Sizes outside RTMP 1.0 §5.4.1's 1..0x7FFFFFFF are ignored, with an error in the log; the previous chunk size stays.

Tests

New test/cmocka/test_rtmp_chunk_size.c sends Set Chunk Size packets through RTMP_ClientPacket:

  • 4096, 1 and 0x7FFFFFFF are taken
  • a 3-byte message is ignored (existing behavior)
  • 0, 0x80000000 and 0xFFFFFFFF leave the size unchanged

It is built exactly like test_rtmp_error (same sources, defines and libraries), so the CMake block is now a foreach over both tests.

The test commit comes first. Locally (MSVC, minimal cmocka stand-in, unused connect code left unresolved) it fails against the old rtmp.c (0 != 4096) and passes with the fix. CI is the first real build.

🤖 Generated with Claude Code

b7216309-jpg and others added 2 commits October 10, 2026 23:21
Sends Set Chunk Size messages through RTMP_ClientPacket: sizes 1 to
0x7FFFFFFF are taken, a short message is ignored, and 0 and sizes with
bit 31 set must be ignored. The last case fails until the next commit.

test_rtmp_chunk_size is built like test_rtmp_error, so both now come
from one foreach.

Refs obs-rust#100

Co-Authored-By: Claude Opus 5.5 <[email protected]>
HandleChangeChunkSize stored the server's Set Chunk Size value in the
int m_inChunkSize unchecked. RTMP_ReadPacket reads min(remaining,
m_inChunkSize) bytes per chunk, and ReadN returns n unchanged for
n <= 0, so:

- 0: no chunk ever adds to the packet, which never completes, and the
  send thread keeps reading headers instead of stopping
- bit 31 set: the size is negative and m_nBytesRead goes backwards,
  below the body allocation

Ignore sizes outside RTMP 1.0's 1 to 0x7FFFFFFF, with an error in the
log.

Fixes obs-rust#100

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@b7216309-jpg

Copy link
Copy Markdown
Contributor Author

Closing in favor of #115, which was opened first with the same fix. I offered the test there.

@zackees

zackees commented Oct 10, 2026

Copy link
Copy Markdown
Member

Rebased onto master. RED→GREEN in Tier 2: at 1295f3b (test only), test_rtmp_chunk_size fails invalid_sizes_are_ignored; with the fix it passes with the Rust port OFF and ON. The local gate passes and is stamped. Marked ready. This supersedes #115 (same fix for #100, but without a test).

@zackees

zackees commented Oct 10, 2026

Copy link
Copy Markdown
Member

Correction to my comment above: it was posted after you had already closed this in favor of #115, and I closed #115 by mistake. I've reopened #115 and will carry your test there as the RED commit, with authorship kept.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

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

2 participants