Skip to content

fix(rtsp): bound interleaved frame copies - #590

Merged
stackia merged 1 commit into
mainfrom
codex/fix-rtsp-interleaved-overflow
Jun 27, 2026
Merged

fix(rtsp): bound interleaved frame copies#590
stackia merged 1 commit into
mainfrom
codex/fix-rtsp-interleaved-overflow

Conversation

@stackia

@stackia stackia commented Jun 27, 2026

Copy link
Copy Markdown
Owner

Summary

This fixes an RTSP TCP interleaved path overflow where the incoming frame length was checked against the 4096-byte RTSP response buffer instead of the 1536-byte zero-copy destination buffer used for RTP forwarding.

Fix

Oversized interleaved frames are now bounded by BUFFER_POOL_BUFFER_SIZE before copying into a pooled packet buffer. Frames above that limit continue through the existing reject/resync path instead of reaching memcpy.

Validation

Built the daemon successfully, ran the RTSP transport e2e coverage, checked e2e collection, and verified the advisory-sized oversized frame with a temporary ASan PoC. The temporary regression check is intentionally not committed.

@stackia
stackia force-pushed the codex/fix-rtsp-interleaved-overflow branch from 8846e22 to 3f29b22 Compare June 27, 2026 08:46
@github-actions

Copy link
Copy Markdown
Contributor

Azure Static Web Apps: Your stage site is ready! Visit it here: https://thankful-water-0a297bf00-590.eastasia.1.azurestaticapps.net

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

Azure Static Web Apps: Your stage site is ready! Visit it here: https://thankful-water-0a297bf00-590.eastasia.1.azurestaticapps.net

@stackia
stackia marked this pull request as ready for review June 27, 2026 08:49
@stackia
stackia requested a review from Copilot June 27, 2026 08:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a potential overflow in the RTSP TCP interleaved (RTP over RTSP) receive path by validating incoming interleaved frame lengths against the actual zero-copy packet buffer capacity used for forwarding, rather than the larger RTSP response parsing buffer.

Changes:

  • Add buffer_pool.h dependency to access BUFFER_POOL_BUFFER_SIZE for bounds checking.
  • Update interleaved frame length sanity check to reject/resync when packet_length > BUFFER_POOL_BUFFER_SIZE, preventing oversized frames from reaching the memcpy into pooled buffers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@stackia
stackia merged commit f0fcfc1 into main Jun 27, 2026
11 checks passed
@stackia
stackia deleted the codex/fix-rtsp-interleaved-overflow branch June 27, 2026 08:50

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3f29b222fa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/rtsp.c
/* Sanity check: prevent processing packets that are too large */
if (packet_length > RTSP_RESPONSE_BUFFER_SIZE - 4) {
/* Sanity check: bound against the zero-copy destination buffer. */
if (packet_length > BUFFER_POOL_BUFFER_SIZE) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Discard oversized frames by length instead of resyncing

When a complete interleaved frame is valid but larger than the 1536-byte pool buffer, this new bound routes it through the generic resync path. That path scans from response_buffer + 1, so an ordinary $ byte inside the oversized RTP/MP2T payload can be mistaken for the next frame marker, leaving the parser aligned to payload bytes and corrupting or dropping subsequent frames. Since the header length is already known after the completeness check, the oversized frame should be consumed by exactly 4 + packet_length bytes rather than resynchronizing inside its payload.

Useful? React with 👍 / 👎.

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.

2 participants