mirror of
https://github.com/pion/webrtc.git
synced 2025-10-05 15:16:52 +08:00
Avoid crash in samplebuilder.PopWithTimestamp
If sample is null, PopWithTimestamp will crash with SIGSEGV.
This commit is contained in:

committed by
Sean DuBois

parent
41243cd179
commit
11f6a65fe2
@@ -300,6 +300,9 @@ func (s *SampleBuilder) Pop() *media.Sample {
|
|||||||
// no sample is compiled).
|
// no sample is compiled).
|
||||||
func (s *SampleBuilder) PopWithTimestamp() (*media.Sample, uint32) {
|
func (s *SampleBuilder) PopWithTimestamp() (*media.Sample, uint32) {
|
||||||
sample := s.Pop()
|
sample := s.Pop()
|
||||||
|
if sample == nil {
|
||||||
|
return nil, 0
|
||||||
|
}
|
||||||
return sample, sample.PacketTimestamp
|
return sample, sample.PacketTimestamp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -379,3 +379,12 @@ func TestSampleBuilderWithPacketReleaseHandler(t *testing.T) {
|
|||||||
t.Errorf("Unexpected packet released by samples built")
|
t.Errorf("Unexpected packet released by samples built")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPopWithTimestamp(t *testing.T) {
|
||||||
|
t.Run("Crash on nil", func(t *testing.T) {
|
||||||
|
s := New(0, &fakeDepacketizer{}, 1)
|
||||||
|
sample, timestamp := s.PopWithTimestamp()
|
||||||
|
assert.Nil(t, sample)
|
||||||
|
assert.Equal(t, uint32(0), timestamp)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user