Skip to content

Commit 11f6a65

Browse files
jechSean-Der
authored andcommitted
Avoid crash in samplebuilder.PopWithTimestamp
If sample is null, PopWithTimestamp will crash with SIGSEGV.
1 parent 41243cd commit 11f6a65

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

pkg/media/samplebuilder/samplebuilder.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@ func (s *SampleBuilder) Pop() *media.Sample {
300300
// no sample is compiled).
301301
func (s *SampleBuilder) PopWithTimestamp() (*media.Sample, uint32) {
302302
sample := s.Pop()
303+
if sample == nil {
304+
return nil, 0
305+
}
303306
return sample, sample.PacketTimestamp
304307
}
305308

pkg/media/samplebuilder/samplebuilder_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,3 +379,12 @@ func TestSampleBuilderWithPacketReleaseHandler(t *testing.T) {
379379
t.Errorf("Unexpected packet released by samples built")
380380
}
381381
}
382+
383+
func TestPopWithTimestamp(t *testing.T) {
384+
t.Run("Crash on nil", func(t *testing.T) {
385+
s := New(0, &fakeDepacketizer{}, 1)
386+
sample, timestamp := s.PopWithTimestamp()
387+
assert.Nil(t, sample)
388+
assert.Equal(t, uint32(0), timestamp)
389+
})
390+
}

0 commit comments

Comments
 (0)