Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue with Packet.PaddingSize #284

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ func (p *Packet) Unmarshal(buf []byte) error {
}
p.PaddingSize = buf[end-1]
end -= int(p.PaddingSize)
} else {
p.PaddingSize = 0
}
if end < n {
return errTooSmall
Expand Down
32 changes: 32 additions & 0 deletions packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,38 @@ func TestBasic(t *testing.T) {
t.Errorf("TestBasic padding unmarshal: got %#v, want %#v", p, parsedPacket)
}

// packet with zero padding following packet with non-zero padding
rawPkt = []byte{
0x90, 0xe0, 0x69, 0x8f, 0xd9, 0xc2, 0x93, 0xda, 0x1c, 0x64,
0x27, 0x82, 0x00, 0x01, 0x00, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x98, 0x36, 0xbe, 0x88, 0x9e,
}
parsedPacket = &Packet{
Header: Header{
Padding: false,
Marker: true,
Extension: true,
ExtensionProfile: 1,
Extensions: []Extension{
{0, []byte{
0xFF, 0xFF, 0xFF, 0xFF,
}},
},
Version: 2,
PayloadType: 96,
SequenceNumber: 27023,
Timestamp: 3653407706,
SSRC: 476325762,
CSRC: []uint32{},
},
Payload: rawPkt[20:],
PaddingSize: 0,
}
if err := p.Unmarshal(rawPkt); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(p, parsedPacket) {
t.Errorf("TestBasic zero padding unmarshal: got %#v, want %#v", p, parsedPacket)
}

// packet with only padding
rawPkt = []byte{
0xb0, 0xe0, 0x69, 0x8f, 0xd9, 0xc2, 0x93, 0xda, 0x1c, 0x64,
Expand Down
Loading