Skip to content

Fix panics in h264 Spreader.Process - #378

Merged
Sean-Der merged 1 commit into
pion:mainfrom
sollniss:push-zpnwplqprtms
Oct 13, 2026
Merged

Sean-Der merged 1 commit into
pion:mainfrom
sollniss:push-zpnwplqprtms

Conversation

@sollniss

@sollniss sollniss commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Spreader.Process panicked on three kinds of received packets:

  • A STAP-A with a single trailing byte read the 2-byte NALU size without a length check.
  • A FU-A fragment small enough to fit in the trailing buffer emitted nothing, then indexed the last packet of an empty slice.
  • An RTP header at least as large as the MTU made the payload budget zero or negative, which panicked in sliceTo or looped forever in spreadFua.

The first and third now return an error. The second is a valid stream, so the fragment is buffered and Process returns no packets.

I also fixed two non-panicking bugs.
Buffered trailing data was overwritten instead of appended to when a fragment emitted nothing, and a FU-A end fragment with an empty payload dereferenced a nil pointer. An empty end FU is now emitted so the end bit is not lost.

Also added FuzzSpreaderProcess and regression tests.

The panics were found using an unreleased static analysis tool written by me. The fixes were implemented with the help of AI.

Process panicked on three kinds of received packet:

- A STAP-A with a single trailing byte read the 2-byte NALU size
  without a length check.
- A FU-A fragment small enough to fit in the trailing buffer emitted
  nothing, then indexed the last packet of an empty slice.
- An RTP header at least as large as the MTU made the payload budget
  zero or negative, which panicked in sliceTo or looped forever in
  spreadFua.

The first and third now return an error. The second is a valid stream,
so the fragment is buffered and Process returns no packets.

Also fix two bugs in the same path: buffered trailing data was
overwritten instead of appended to when a fragment emitted nothing,
and a FU-A end fragment with an empty payload dereferenced a nil
pointer. An empty end FU is now emitted so the end bit is not lost.

Add FuzzSpreaderProcess and regression tests.
@codecov

codecov Bot commented Oct 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.14%. Comparing base (3a98767) to head (0166c06).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #378      +/-   ##
==========================================
+ Coverage   87.48%   88.14%   +0.65%     
==========================================
  Files          28       28              
  Lines        3165     3171       +6     
==========================================
+ Hits         2769     2795      +26     
+ Misses        396      376      -20     
Flag Coverage Δ
go 88.14% <100.00%> (+0.65%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JoTurk JoTurk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you, we should move Spreader to pion/format in the next major release, since we don't use it directly in webrtc.

@Sean-Der
Sean-Der merged commit e24c716 into pion:main Oct 13, 2026
19 checks passed
@JoTurk

JoTurk commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

@Sean-Der I realized that this had a correctness bug this is why i didn't merge it, but it avoids the panic, I'll follow up with the fix.

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.

3 participants