mirror of
https://github.com/livekit/livekit.git
synced 2026-11-23 02:29:22 +00:00
rtc: guard nil source in BroadcastDataMessageForRoom (#5110)
Relayed unlabeled data arrives with no local source participant, and
the sender identity lookup dereferenced it.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 1681f36610)
This commit is contained in:
1 parent
2ab2e15140
commit
c83376bc00
2 files changed
+25
-2
No files matched your search
+10
-2
@@ -2180,12 +2180,20 @@ func BroadcastDataPacketForRoom(
|
||||
}
|
||||
|
||||
func BroadcastDataMessageForRoom(r types.Room, source types.LocalParticipant, data []byte, logger logger.Logger) {
|
||||
// source is nil for data relayed from a remote node
|
||||
var sourceID livekit.ParticipantID
|
||||
var sourceIdentity livekit.ParticipantIdentity
|
||||
if source != nil {
|
||||
sourceID = source.ID()
|
||||
sourceIdentity = source.Identity()
|
||||
}
|
||||
|
||||
utils.ParallelExec(r.GetLocalParticipants(), dataForwardLoadBalanceThreshold, 1, func(op types.LocalParticipant) {
|
||||
if source != nil && op.ID() == source.ID() {
|
||||
if source != nil && op.ID() == sourceID {
|
||||
return
|
||||
}
|
||||
|
||||
op.SendDataMessageUnlabeled(data, false, source.Identity())
|
||||
op.SendDataMessageUnlabeled(data, false, sourceIdentity)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -773,6 +773,21 @@ func TestDataChannel(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("unlabeled broadcast without source", func(t *testing.T) {
|
||||
rm := newRoomWithParticipants(t, testRoomOpts{num: 2})
|
||||
defer rm.Close(types.RoomCloseReasonUnknown)
|
||||
|
||||
BroadcastDataMessageForRoom(rm, nil, []byte("relayed"), rm.logger)
|
||||
|
||||
for _, op := range rm.GetParticipants() {
|
||||
fp := op.(*typesfakes.FakeLocalParticipant)
|
||||
require.Equal(t, 1, fp.SendDataMessageUnlabeledCallCount())
|
||||
got, _, sender := fp.SendDataMessageUnlabeledArgsForCall(0)
|
||||
require.Equal(t, []byte("relayed"), got)
|
||||
require.Empty(t, sender)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("publishing disallowed", func(t *testing.T) {
|
||||
rm := newRoomWithParticipants(t, testRoomOpts{num: 2})
|
||||
defer rm.Close(types.RoomCloseReasonUnknown)
|
||||
|
||||
Reference in new issue
Block a user