fix(rtp): reset PaddingSize when Padding bit is unset (closes #140)#142
fix(rtp): reset PaddingSize when Padding bit is unset (closes #140)#142Booyaka101 wants to merge 1 commit into
Conversation
) `rtpUnmarshalPayload` reuses the *rtp.Packet across reads. When a packet with Padding=true was followed by a packet with Padding=false, the second packet's PaddingSize was left stale at the first packet's value. The downstream payload-size calculation in rtp_packet_reader.go:153 and rtp_session.go:265 subtracts pkt.PaddingSize unconditionally, so stale values truncate the second packet's payload. Reset p.PaddingSize = 0 in the else branch, matching pion/rtp's own Unmarshal behavior (packet.go:240-243). Reported and root-caused by @brandon-hc. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
I am having hard time to follow on this, but we can merge this as I see. |
|
Sure — boiling it down: Diago reuses one The one-line fix sets |
Summary
rtpUnmarshalPayloadreuses the same*rtp.Packetacross reads. When a packet withPadding=trueis followed by one withPadding=false, the second packet'sPaddingSizefield is left stale at the first packet's value. The downstream payload-size calculation (rtp_packet_reader.go:153,rtp_session.go:265) subtractspkt.PaddingSizeunconditionally, so the stale value truncates the second packet's payload.Reported and root-caused by @brandon-hc in #140.
Fix
Reset
p.PaddingSize = 0in the else branch ofrtpUnmarshalPayload, matching pion/rtp's ownUnmarshalbehavior atpacket.go:240-243.end := len(buf) if p.Header.Padding { p.PaddingSize = buf[end-1] end -= int(p.PaddingSize) + } else { + p.PaddingSize = 0 }The downstream consumers at
rtp_packet_reader.go:153andrtp_session.go:265are unchanged — the fix is at the unmarshal layer where the field gets populated.Regression test
TestRTPUnmarshalResetsPaddingSizeexercises the exact reuse scenario: marshal a padded packet, unmarshal intopkt, then marshal an unpadded packet and unmarshal into the samepkt. Assertspkt.PaddingSize == 0and the full payload survives.Verification
FAIL: expected 0x0, actual 0x4atrtp_parse_test.go:56— confirms the test exercises the bugPASS(regression test + fullgo test ./media/suite, 1.7s)PASSOut of scope
pkt.PaddingSizefield is now deprecated in favor ofpkt.Header.PaddingSize. Diago still uses the legacy field; migrating is a larger structural change and a separate concern.